Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Empty list and null (Francesco Ariis)
   2. Re:  Empty list and null (trent shipley)
   3. Re:  Empty list and null (Theodore Lief Gannon)


----------------------------------------------------------------------

Message: 1
Date: Sat, 18 Aug 2018 11:36:56 +0200
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Empty list and null
Message-ID: <20180818093656.gd2iejhgx7jbv...@x60s.casa>
Content-Type: text/plain; charset=utf-8

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 `[]`.



------------------------------

Message: 2
Date: Sat, 18 Aug 2018 03:08:37 -0700
From: trent shipley <trent.ship...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Empty list and null
Message-ID:
        <CAEFLyb+tc4X-9HPC0=z4NW_zHWncoa1VN+2=zx0mkzhicxx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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...@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@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-0001.html>

------------------------------

Message: 3
Date: Sat, 18 Aug 2018 03:35:40 -0700
From: Theodore Lief Gannon <tan...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Empty list and null
Message-ID:
        <cajopsub9sozwe+nxog649gggq2mp_+hrvemzdjquxs8b_gt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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.ship...@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...@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@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> Beginners@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-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 122, Issue 8
*****************************************

Reply via email to