Send Beginners mailing list submissions to
[email protected]
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
[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: Numeric Integer vs Integer (Kim-Ee Yeoh)
2. Re: Numeric Integer vs Integer (goforgit .)
----------------------------------------------------------------------
Message: 1
Date: Wed, 23 Sep 2015 15:48:13 +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] Numeric Integer vs Integer
Message-ID:
<capy+zdtjnva0x42soy0h0ynwc-i_jy222fwvqlh+ys6rwvt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Wed, Sep 23, 2015 at 2:51 PM, goforgit . <[email protected]> wrote:
> What about the following?
>
> data List a = Empty | Add a (List a)
>
> What does the a mean and why is it possible to put it there?
In addition to the good answers already given, it helps to think of it this
way:
Here's a list of Bools:
data ListBool = EmptyListBool | AddListBool Bool ListBool
Here's a list of Chars:
data ListChar = EmptyListChar | AddListChar Char ListChar
Here's a list of Ints:
data ListInt = EmptyListInt | AddListInt Int ListInt
Well just look at all that repetition!
Surely there must be a way to keep DRY and abstract over all that?
Let's see: what's common to all of the above? What stays the same? What
changes?
Here's something that tries to express and separate out what's "fixed" and
what's "insert type here":
data ListX = Empty | Add X ListX
We're close.
That almost but doesn't quite work, because Haskell treats capital X as a
concrete type, like Bool and Char and Int.
What we want is a type _variable_. And Haskell gives us that, if we use
lower-case letters:
data List x = Empty | Add x (List x)
The parens is needed to distinguish against
data List x = Empty | Add x List x
which doesn't work for reasons you can probably guess.
Finally, it's convention to use type variables a b c and not x y z.
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150923/fe2f6b0f/attachment-0001.html>
------------------------------
Message: 2
Date: Wed, 23 Sep 2015 12:39:37 +0200
From: "goforgit ." <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Numeric Integer vs Integer
Message-ID:
<CAHzzbMAnYkKN-rzW=h+2ngzgPLvOYYG9WrLOrLAMX6=xocd...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thank you guys, very good descriptions given on my question. Together with
your answers and the analogy of it being somewhat similar to something in
C++ made me understand how it works. Again many thanks!
On Wed, Sep 23, 2015 at 10:48 AM, Kim-Ee Yeoh <[email protected]> wrote:
>
> On Wed, Sep 23, 2015 at 2:51 PM, goforgit . <[email protected]> wrote:
>
>> What about the following?
>>
>> data List a = Empty | Add a (List a)
>>
>> What does the a mean and why is it possible to put it there?
>
>
> In addition to the good answers already given, it helps to think of it
> this way:
>
> Here's a list of Bools:
>
> data ListBool = EmptyListBool | AddListBool Bool ListBool
>
> Here's a list of Chars:
>
> data ListChar = EmptyListChar | AddListChar Char ListChar
>
> Here's a list of Ints:
>
> data ListInt = EmptyListInt | AddListInt Int ListInt
>
> Well just look at all that repetition!
>
> Surely there must be a way to keep DRY and abstract over all that?
>
> Let's see: what's common to all of the above? What stays the same? What
> changes?
>
> Here's something that tries to express and separate out what's "fixed" and
> what's "insert type here":
>
> data ListX = Empty | Add X ListX
>
> We're close.
>
> That almost but doesn't quite work, because Haskell treats capital X as a
> concrete type, like Bool and Char and Int.
>
> What we want is a type _variable_. And Haskell gives us that, if we use
> lower-case letters:
>
> data List x = Empty | Add x (List x)
>
> The parens is needed to distinguish against
>
> data List x = Empty | Add x List x
>
> which doesn't work for reasons you can probably guess.
>
> Finally, it's convention to use type variables a b c and not x y z.
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150923/8d9c9a35/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 87, Issue 14
*****************************************