Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Empty type (Nicholas Vanderweit)
2. Re: Empty type (Kim-Ee Yeoh)
----------------------------------------------------------------------
Message: 1
Date: Fri, 25 Oct 2013 11:26:28 -0600
From: Nicholas Vanderweit <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Empty type
Message-ID:
<CAN0ny8bb1=Pj9tjqo2zdv9+ckHpqk-v85Utn9Ta2+cW=G=d...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Not sure if this is haskell-beginners material, but it's possible in a lazy
language like Haskell to define an inhabitant of NotVoid recursively:
let x = NotVoid x in x
Or, alternatively, using fix from Data.Function:
fix NotVoid
This gives NotVoid (NotVoid (NotVoid (...)))
Nick
On Fri, Oct 25, 2013 at 5:54 AM, Brent Yorgey <[email protected]>wrote:
> On Fri, Oct 25, 2013 at 12:44:06PM +0900, KwangYul Seo wrote:
> > Hello,
> >
> > It seems there are three different ways to declare an empty type in
> Haskell.
> >
> > http://www.haskell.org/haskellwiki/Empty_type
> >
> > 1) data E0 = E0
>
> This one is not empty, as others have pointed out. It is inhabited by _|_
> and E0.
>
> > 2) newtype Void = Void Void
>
> This one is in fact empty (that is, only inhabited by _|_), but it
> depends on the fact that newtype constructors do not add any laziness.
> The same thing done with 'data',
>
> data NotVoid = NotVoid NotVoid
>
> is not empty, because it is inhabited by
>
> _|_, NotVoid _|_, NotVoid (NotVoid _|_), ...
>
> With the data declaration, these are all different. With the newtype,
> they are all equal to _|_. This is a bit of a technical point,
> however; if I were you I wouldn't worry about it at this point. It
> sounds like the most important thing for you to understand is below:
>
> > I'd like to know how the second trick works. Is it possible to create a
> new
> > type from itself? How should I interpret this?
>
> Yes, it is possible to create a new type from itself! This is called
> a "recursive data type", and they are the bread and butter of Haskell
> programming. For some other less silly/trivial examples, consider
>
> data IntList = Nil | Cons Int IntList
>
> data BTree a = Empty | Node a (BTree a) (BTree a)
>
> both of which are recursive types.
>
> -Brent
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131025/612c0d2d/attachment-0001.html>
------------------------------
Message: 2
Date: Sat, 26 Oct 2013 03:12:36 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Empty type
Message-ID:
<capy+zdqwk4ghl8a4hdfya-cg_62vnt63-6lnnaayjahu4wl...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Sat, Oct 26, 2013 at 12:26 AM, Nicholas Vanderweit <
[email protected]> wrote:
> Or, alternatively, using fix from Data.Function:
>
> fix NotVoid
>
Yes, and all of them are indistinguishable from bottom or 'undefined ::
forall a. a', the ghost that inhabits all types, including the empty one:
Void.
What trips up beginners is the interpretation of indistinguishable-ness. At
the level of denotational design, 'undefined' and 'error "(sadface)"' are
to be treated as equal, although beginners would point out: "hey look, I
get different output!"
Call it denotational design, or call it beautiful FP modelling, this stuff
is really where it's at.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131026/8eb733ee/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 64, Issue 38
*****************************************