[Haskell-beginners] Parametrizing [] as an instance of the Functor type class

Olumide 50295 at web.de
Tue Jan 5 13:59:00 UTC 2016


On 01/01/2016 19:41, Alexander Berntsen wrote:
>> Can you please give an example of [] used as a type constructor?
> Whenever you write a list type, e.g. [Int], you are using [] as a type
> constructor. The fact that you can write [Int] instead of '[] Int' is
> simply syntax sugar.
>
> We can imagine the simple function that returns the first element of a
> list, if there is one.
>
> head :: [a] -> Maybe a
> head []     = Nothing
> head (x:xs) = Just x
>
> Here we use [] both on type and term level. On type level we use it to
> mean a list of 'a's, and on term level we use it to mean the empty list.

Out of curiosity, is [] defined as type constructor _and_ term level at 
the library level or in the language/compiler? (BTW, google tells me 
"term-level" has a special meaning that I do not yet know.)

Note: I've deferred reading your explanation of kinds because (1) I am 
still trying to get to grips with Functors and (2) the section on kinds 
is just two pages away from where I am in the book. So if these 
questions are answered by kinds please let me know.

Thanks for your patience,

- Olumide



More information about the Beginners mailing list