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:  question about list processing (David McBride)
   2. Re:  question about list processing (Dennis Raddle)
   3.  Why this order of parameters (martin)
   4. Re:  question about list processing (Alex Hammel)
   5.  My First Haskell Project--Please give feedback! (Thomas Jakway)


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

Message: 1
Date: Thu, 12 Nov 2015 09:32:29 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] question about list processing
Message-ID:
        <can+tr42dqkskhyw0z18tmicynkmrcs1hi2+txugokzwf+so...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

There was some real controversy over this change.  People were strongly
opposed to the change for exactly the reason you gave (among others), that
it is hard for beginners.  However, there was enough momentum that it went
through, and now things like fmap and length work on a wide variety of data
types.  You can google ftp haskell controversy for more info.

On Thu, Nov 12, 2015 at 8:48 AM, Dennis Raddle <[email protected]>
wrote:

> Speaking of lists and history, I noticed that a lot of library functions
> which were formerly defined over lists (when I first looked at Haskell six
> years ago) are now defined on Traversable, which makes it a lot harder for
> beginners to read the documentation. I have been playing with Haskell for
> five years, but not much, so I'm still a beginner. I just mentally
> substitute lists when I see Traversable.
>
> I only really use lists and Maybe, as far as instances of the typeclasses
> go. That's only two types, but a lot to learn!
>
> D
>
>
>
>
> On Thu, Nov 12, 2015 at 5:42 AM, akash g <[email protected]> wrote:
>
>>
>> http://stackoverflow.com/questions/7463500/why-do-we-have-map-fmap-and-liftm
>> have very good answers on this.
>>
>> On Thu, Nov 12, 2015 at 7:11 PM, akash g <[email protected]> wrote:
>>
>>> map is specialized for lists while fmap is for any functors.  Its
>>> presence is historical.  Prefer fmap over map.
>>>
>>> On Thu, Nov 12, 2015 at 7:03 PM, Dennis Raddle <[email protected]>
>>> wrote:
>>>
>>>> Just after I posted that question, I started driving home, and on the
>>>> drive I thought of your answer. I think I'm starting to ask the right
>>>> questions when I'm programming in Haskell. Like redundancy and bloat is a
>>>> sure sign that a more witty expression is available, and that I should
>>>> consult the typeclasses.
>>>>
>>>> Second, I am not used to the implications of laziness, so it took me a
>>>> while to hit on your solution because I keep thinking you have to map
>>>> something over the whole list, and that if you only want to map it over the
>>>> head, you are stuck.
>>>>
>>>> You can use 'map' also, instead of 'fmap', right? Is 'map' just 'fmap'
>>>> for lists?
>>>>
>>>> D
>>>>
>>>>
>>>> _______________________________________________
>>>> 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/20151112/7ac579dd/attachment-0001.html>

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

Message: 2
Date: Thu, 12 Nov 2015 06:58:25 -0800
From: Dennis Raddle <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] question about list processing
Message-ID:
        <cakxlvoqkontxvnrotnsnzf2tt+27nsfxcg_6dm+6me4v1gv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Oh I needed join.

computeHead :: (a -> [b]) -> [a] -> [b]
computeHead f = join . take 1 . fmap f

That's because

f :: a -> [b]

not

f: a -> b


On Thu, Nov 12, 2015 at 5:22 AM, Martin Vlk <[email protected]> wrote:

> How about:
>
> computeHead f = take 1 . fmap f
>
> Martin
>
> Dennis Raddle:
> > What would be an elegant way of writing this
> >
> > computeHead :: (a -> [b]) -> [a] -> [b]
> >
> > Where when [a] is null, it returns a null list, but when [a] contains one
> > or more elements, it applies the given function to the head of a and
> > returns that? Is there some existing typeclass operator that facilitates
> > this?
> >
> > You can write
> >
> > computeHead _ [] = []
> > computeHead f (x:_) = f x
> >
> > But that first line seems suspicious to me... it makes me think about how
> > in the list Monad, an empty list falls through. But I can't quite make it
> > work.
> >
> >
> >
> > _______________________________________________
> > 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/20151112/962131e5/attachment-0001.html>

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

Message: 3
Date: Thu, 12 Nov 2015 16:52:06 +0100
From: martin <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Why this order of parameters
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

Hello all,

there are two functions, where the order of parameters confuses me. Ons is

runState :: State s a -> s -> (a, s)

I understand that in the constructor s has to be first, so we can turn (State 
s) into a monad. But why doesn't s come
first in the result too, as in

runState :: State s a -> s -> (s, a)


The other example is foldl, foldr

foldl :: (a -> b -> a) -> a -> [b] -> a
foldr :: (a -> b -> b) -> b -> [a] -> b

For once the list is a list of as in foldl, but a list of as in foldr. Now that 
can be fixed with renaming the type
parameters

foldr :: (b -> a -> a) -> a -> [b] -> a

this is the exact same thing and resembles more the type of foldl. But still 
the function argument has its parameters
flipped. foldl's function takes the list element as second parameter and 
foldr's takes it as first parameter.

Why is that so?


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

Message: 4
Date: Thu, 12 Nov 2015 16:20:28 +0000
From: Alex Hammel <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] question about list processing
Message-ID:
        <ca+_xfeojz1i93pmvjrayqxp_y+d-tv_bzzvklbkhtu5yooa...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

With the join it's the same thing as:

computeHead :: (a -> [b]) -> [a] -> [b]
computeHead f xs = take 1 xs >>= f


On Thu, 12 Nov 2015 at 06:58 Dennis Raddle <[email protected]> wrote:

> Oh I needed join.
>
> computeHead :: (a -> [b]) -> [a] -> [b]
> computeHead f = join . take 1 . fmap f
>
> That's because
>
> f :: a -> [b]
>
> not
>
> f: a -> b
>
>
> On Thu, Nov 12, 2015 at 5:22 AM, Martin Vlk <[email protected]> wrote:
>
>> How about:
>>
>> computeHead f = take 1 . fmap f
>>
>> Martin
>>
>> Dennis Raddle:
>> > What would be an elegant way of writing this
>> >
>> > computeHead :: (a -> [b]) -> [a] -> [b]
>> >
>> > Where when [a] is null, it returns a null list, but when [a] contains
>> one
>> > or more elements, it applies the given function to the head of a and
>> > returns that? Is there some existing typeclass operator that facilitates
>> > this?
>> >
>> > You can write
>> >
>> > computeHead _ [] = []
>> > computeHead f (x:_) = f x
>> >
>> > But that first line seems suspicious to me... it makes me think about
>> how
>> > in the list Monad, an empty list falls through. But I can't quite make
>> it
>> > work.
>> >
>> >
>> >
>> > _______________________________________________
>> > 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/20151112/5880b41c/attachment-0001.html>

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

Message: 5
Date: Thu, 12 Nov 2015 11:34:58 -0500
From: Thomas Jakway <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] My First Haskell Project--Please give
        feedback!
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed

Hi everyone!  I'm trying to write a blackjack simulator and would really 
appreciate advice on the code.

I wrote about lots of specific things in an /r/haskell post:

https://www.reddit.com/r/haskell/comments/3sjs0y/my_first_haskell_projectplease_give_feedback/

And the code is here:
https://github.com/tjakway/blackjack-simulator/blob/master/src/Cards.hs

(sorry if it's annoying to have to follow a link, thought it'd be better 
than just copy + pasting a huge blob here)

Thanks in advance!


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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 89, Issue 20
*****************************************

Reply via email to