[Haskell-beginners] Empty list and null

trent shipley trent.shipley at gmail.com
Sat Aug 18 10:08:37 UTC 2018


OK. That makes total sense.  And a little experimentation with GHCi or
reading the prelude would have prevented my spamming the list.

What about the tacked on question about nullity in "core" Haskell?

On Sat, Aug 18, 2018 at 2:37 AM Francesco Ariis <fa-ml at ariis.it> wrote:

> Hello Trent,
>
> On Sat, Aug 18, 2018 at 02:13:25AM -0700, trent shipley wrote:
> > Why does Haskell so often seem to treat [] as a general null.
> >
> > For example I know 0 : 1 : [] gives [0, 1].
> >
> > But shouldn't it produce a type fault in a consistent world?
> >
> > Int:Int:List isn't properly a list.  It mixes types.
>
> `:` is not syntactic sugar, but a data constructor and behaves like one!
>
>     λ> :type (:)
>     (:) :: a -> [a] -> [a]
>
> "Give me an `a` and a list of `a`, I will return a list."
>
> The `empty list` ([]) is polymorphic:
>
>     λ> :t []
>     [] :: [a]
>
> (it could be an empty list of strings, of ints, of dromedaries),
> so `3:[]` is well typed.
>
> Note that `3:[]:4` will not type-check and that to build a list, you
> *have* to start with a `[]`.
>
> _______________________________________________
> 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/20180818/3eba8ecc/attachment.html>


More information about the Beginners mailing list