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 (goforgit .)
   2. Re:  foldl on Bool:s (goforgit .)
   3. Re:  Numeric Integer vs Integer (Brandon Allbery)
   4. Re:  Numeric Integer vs Integer (goforgit .)
   5. Re:  foldl on Bool:s (Rein Henrichs)


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

Message: 1
Date: Fri, 25 Sep 2015 20:10:26 +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:
        <CAHzzbMBxUX+qKk9rf0-qsY1QNngcmEoOPm8=8vnumnkgmt1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 . <[email protected]> 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 . <[email protected]> wrote:
>
>> Thanks Brandon, that cleared things up!
>>
>> On Mon, Sep 21, 2015 at 8:39 PM, Brandon Allbery <[email protected]>
>> wrote:
>>
>>>
>>> On Mon, Sep 21, 2015 at 2:23 PM, goforgit . <[email protected]> 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
>>> [email protected]
>>> [email protected]
>>> unix, openafs, kerberos, infrastructure, xmonad
>>> http://sinenomine.net
>>>
>>> _______________________________________________
>>> 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/20150925/9045aa91/attachment-0001.html>

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

Message: 2
Date: Fri, 25 Sep 2015 20:10:50 +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] foldl on Bool:s
Message-ID:
        <CAHzzbMC0C2p1PFMWFLvuxj+jOfgy5eKCrjFN=tqwcnihfbv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks I got it now :)

On Thu, Sep 24, 2015 at 9:45 PM, Kostiantyn Rybnikov <[email protected]> wrote:

> Hi.
>
> Your function gets passed numbers one by one in the place of x, and its
> previous result in the place of acc, and it returns a Bool. Initial value
> in place of acc parameter ("previous result") is put as False (since you
> begin with answer "no" to question "is it elem?").
>
> Hope this helps.
> 24 ???. 2015 19:04 "goforgit ." <[email protected]> ????:
>
>> Reading http://learnyouahaskell.com/higher-order-functions
>>
>> I understand that with the function
>>
>> sum' :: (Num a) => [a] -> a
>> sum' = foldl (+) 0
>>
>> the call
>>
>> ghci>>> sum' [1,2,3]
>>
>> will be evaluated as
>>
>> 0 + 1 + 2 + 3 = 6
>>
>> But what about the function
>>
>> elem' :: (Eq a) => a -> [a] -> Bool
>> elem' y ys = foldl (\acc x -> if x == y then True else acc) False ys
>>
>> and calling it with
>>
>> ghci>>> elem' 3 [1,2,3]
>>
>> How is that evaluated to True by foldl in elem'?
>>
>> Thanks in advance for any explanation to this!
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> 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/20150925/4dafd2aa/attachment-0001.html>

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

Message: 3
Date: Fri, 25 Sep 2015 14:20:29 -0400
From: Brandon Allbery <[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:
        <CAKFCL4UXOYd7LhPEtwg=s1bqunjv0ogolye9tyjlzenakpv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Fri, Sep 25, 2015 at 2:10 PM, goforgit . <[email protected]> wrote:

> Is it possible to make the list an instance of something in order to use
> for example takeWhile on List?


Not presently for takeWhile; it's specific to the built-in list type.
Things are gradually being migrated to Foldable and Traversable, though.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150925/8691a2ae/attachment-0001.html>

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

Message: 4
Date: Fri, 25 Sep 2015 21:02:04 +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:
        <CAHzzbMA9CBKYwYODOT=_cdmbmyyhotnkt8i7lpzyeqakvv_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Alrighty then, thanks brandon!

On Fri, Sep 25, 2015 at 8:20 PM, Brandon Allbery <[email protected]>
wrote:

> On Fri, Sep 25, 2015 at 2:10 PM, goforgit . <[email protected]> wrote:
>
>> Is it possible to make the list an instance of something in order to use
>> for example takeWhile on List?
>
>
> Not presently for takeWhile; it's specific to the built-in list type.
> Things are gradually being migrated to Foldable and Traversable, though.
>
> --
> brandon s allbery kf8nh                               sine nomine
> associates
> [email protected]
> [email protected]
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> _______________________________________________
> 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/20150925/cc049ba4/attachment-0001.html>

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

Message: 5
Date: Fri, 25 Sep 2015 22:16:23 +0000
From: Rein Henrichs <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] foldl on Bool:s
Message-ID:
        <cajp6g8ynba2-eu8epupypmw4xkejreimyzphe3skr+yo04u...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Note that you would like the elem function to stop at the matching element
and return True rather than checking the rest of the list needlessy, which
can be done with foldr but not with foldl. The actual implementation of
elem does this, so you can say:

> elem 1 [1..]
True

which would fail to terminate with the foldl version.

On Fri, Sep 25, 2015 at 11:10 AM goforgit . <[email protected]> wrote:

> Thanks I got it now :)
>
> On Thu, Sep 24, 2015 at 9:45 PM, Kostiantyn Rybnikov <[email protected]>
> wrote:
>
>> Hi.
>>
>> Your function gets passed numbers one by one in the place of x, and its
>> previous result in the place of acc, and it returns a Bool. Initial value
>> in place of acc parameter ("previous result") is put as False (since you
>> begin with answer "no" to question "is it elem?").
>>
>> Hope this helps.
>> 24 ???. 2015 19:04 "goforgit ." <[email protected]> ????:
>>
>>> Reading http://learnyouahaskell.com/higher-order-functions
>>>
>>> I understand that with the function
>>>
>>> sum' :: (Num a) => [a] -> a
>>> sum' = foldl (+) 0
>>>
>>> the call
>>>
>>> ghci>>> sum' [1,2,3]
>>>
>>> will be evaluated as
>>>
>>> 0 + 1 + 2 + 3 = 6
>>>
>>> But what about the function
>>>
>>> elem' :: (Eq a) => a -> [a] -> Bool
>>> elem' y ys = foldl (\acc x -> if x == y then True else acc) False ys
>>>
>>> and calling it with
>>>
>>> ghci>>> elem' 3 [1,2,3]
>>>
>>> How is that evaluated to True by foldl in elem'?
>>>
>>> Thanks in advance for any explanation to this!
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> 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/20150925/7b33559c/attachment.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 17
*****************************************

Reply via email to