[Haskell-beginners] Numeric Integer vs Integer
goforgit .
teztingit at gmail.com
Fri Sep 25 18:10:26 UTC 2015
Again, I have a follow up question related to that list.
Is it possible to make the list an instance of something in order to use
for example takeWhile on List?
Thanks in advance!
On Wed, Sep 23, 2015 at 9:51 AM, goforgit . <teztingit at gmail.com> wrote:
> I have a follow up question, I hope it's alright.
>
> 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?
>
>
> On Tue, Sep 22, 2015 at 4:54 PM, goforgit . <teztingit at gmail.com> wrote:
>
>> Thanks Brandon, that cleared things up!
>>
>> On Mon, Sep 21, 2015 at 8:39 PM, Brandon Allbery <allbery.b at gmail.com>
>> wrote:
>>
>>>
>>> On Mon, Sep 21, 2015 at 2:23 PM, goforgit . <teztingit at gmail.com> wrote:
>>>
>>>> Could someone explain to me the difference between the following?
>>>>
>>>> data Atype = Numeric Integer | A | B C
>>>>
>>>> and
>>>>
>>>> data Atype = Integer | A | B C
>>>>
>>>
>>> The second one is an enumeration with three values: "Integer" (which is
>>> *not* an integer, nor does it contain one), "A", and "B" which as written
>>> there takes a value of some unspecified type C as a parameter.
>>> The first one is a enumeration with three values: "Numeric" which takes
>>> an Integer as a parameter, "A", and "B" which takes a value of some
>>> unspecified type C as a parameter.
>>>
>>> Note that the "Integer" in the second one has *nothing whatsoever* to do
>>> with the *type* Integer.
>>>
>>> Remember that you must always provide a data constructor with "data";
>>> you cannot simply say "data MyInt = Integer" to "wrap" an Integer, because
>>> you have not said what to wrap it *in*. (You may have intended to create a
>>> type alias, though; that would be "type", not "data".) A "data" always
>>> requires a data constructor name, so the compiler can tell when you are
>>> talking about a value of that type by looking for the constructor.
>>>
>>> --
>>> brandon s allbery kf8nh sine nomine
>>> associates
>>> allbery.b at gmail.com
>>> ballbery at sinenomine.net
>>> unix, openafs, kerberos, infrastructure, xmonad
>>> http://sinenomine.net
>>>
>>> _______________________________________________
>>> 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/20150925/9045aa91/attachment.html>
More information about the Beginners
mailing list