[Haskell-beginners] Empty list and null

Theodore Lief Gannon tanuki at gmail.com
Sat Aug 18 10:35:40 UTC 2018


The nullary constructor, as far as the term has meaning in most languages,
is () a.k.a. unit. It takes no arguments, and returns a valid data type.

There is, however, an even less populated type: Void has no legal values at
all! If nullary is arity 0, this is roughly arity i. It is still useful as
a type-level encoding of "impossible outcome" in parametric code.

On Sat, Aug 18, 2018, 3:09 AM trent shipley <trent.shipley at gmail.com> wrote:

> 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
>>
> _______________________________________________
> 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/df6463d1/attachment.html>


More information about the Beginners mailing list