[Haskell-beginners] Parametrizing [] as an instance of the Functor type class
Rein Henrichs
rein.henrichs at gmail.com
Tue Jan 5 18:57:09 UTC 2016
[1,2,3] is [Int] or [] Int (if we take the numbers to be Ints for
simplicity). It is the [] type constructor applied to the Int type.
On Tue, Jan 5, 2016 at 5:59 AM Olumide <50295 at web.de> wrote:
> 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160105/978b12d1/attachment.html>
More information about the Beginners
mailing list