Original post is here.
This explanation should be combined with 24 Days of GHC Extensions: Rank N Types (see related hypothes.is note).
Original post is here.
This explanation should be combined with 24 Days of GHC Extensions: Rank N Types (see related hypothes.is note).
Commonly the above definition is called the identity function. But in fact we should think of it as a whole family of functions. We should really say that id is an identity function for all types a. In other words, for every type T you might come up with, there is an identity function called id, which is of type T -> T. This is the type-checker’s view anyway, and by turning on the RankNTypes extension we can be explicit about that in our code: {-# LANGUAGE RankNTypes #-} id :: forall a. a -> a id x = x
This is such a nice description of forall
. It should be combined with forall
is the type-level "lambda" (also saved it here).
In other words you cannot choose the definition of a value based on its type (for now).
What does this mean?