Reputation: 4038
In GHCI, the type of id
is:
Prelude> :t id
id :: a -> a
But if I define my own id
function, why is the name of the type variable t
? Is there a difference between t
and a
?
Prelude> let identity x = x
Prelude> :t identity
identity :: t -> t
Upvotes: 2
Views: 458
Reputation: 120741
This has actually the same answer as if I were asking
If I define my own version of your version asPrelude> let identity' q = q
why is the name of the value variableq
? Is there a difference betweenq
andx
?
The crucial thing about parameter variables in general is that their names are basically arbitrary. It's a fundamental property of lambda-calculus: α-equivalence. We merely replace \x -> x
with \q -> q
(or, in lambda-style, λx.x
with λq.q
). And indeed type variables are parameters as well, though it doesn't really look like they are. But under the hood, Haskell polymorphic signatures should be read as System F, so really we have Λα . α -> α
, usually written forall a . a -> a
. Which is obviously equivalent to forall t . t -> t
.
Upvotes: 6
Reputation: 15959
There is no difference between a
and t
, they are called Type variables and stand for any type you can have. Note that they are written in lowercase letters where types are written with an uppercase letter at the beginning (except for lists, who have special syntax).
In addition if you write a file and load it into ghci by ghci testmodule.hs
module Testmodule where
identity :: b -> b
identity x = x
then ghci will show you exactly the letter you used in your definition.
Upvotes: 9