Type of id function in Haskell

fouronnes

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
epsilonhalbe

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related