a is a type variable. Think of it as one that can be replaced with any other type . However, all occurrences of a in a signature of the same type must be replaced by the same specific type.
So, if map has this signature ...
(a -> msg) -> Cmd a -> Cmd msg
... that would be a valid substitution:
(Bool -> MyMessage) -> Cmd Bool -> Cmd MyMessage
( msg is another type variable)
... although this would be a wrong replacement:
(Bool -> MyMessage) -> Cmd MyMessage -> Cmd Bool -- note the mismatched type variables
The presence of type variables provides great flexibility, because a generic function of type map can be reused with all types of different types.
source share