In Haskell, I learned that there are type variables (for example, id :: a -> a) that apply to signature types and types (for example Maybe :: * -> *) that apply to type constructors and class types. To store values, the type must have the form *(be a specific type).
We use type variables to include polymorphism: Nothing :: Maybe ameans that a constant Nothingcan belong to a family of possible types. This leads me to believe that type parameters kinding and type serve the same purpose; wouldn't the last code sample work as simple Nothing :: Maybeas where the type type Maybe stays with a view * -> *to indicate that the type belongs to the generic family?
It seems that we are making an empty parameter ( * -> *) and filling it with a variable of type ( a), which represents the same level of variance.
We see this behavior in another example:
>>> :k Either
Either :: * -> * -> *
>>> :t Left ()
Left () :: Either () b
>>> :t Right ()
Right () :: Either a ()
Why is it theoretically necessary to distinguish between types and type variables?
source
share