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:  figured out use for join! (Frerich Raabe)
   2. Re:  figured out use for join! (Marcin Mrotek)
   3. Re:  figured out use for join! (Frerich Raabe)
   4.  question about list processing (Dennis Raddle)


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

Message: 1
Date: Wed, 11 Nov 2015 23:01:29 +0100
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] figured out use for join!
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed

On 2015-11-11 22:12, Dennis Raddle wrote:
> f k m = case M.lookup k m of
>   Nothing -> Nothing
>   Just xs -> listToMaybe xs
> 
> But the case "Nothing -> Nothing" is suspicious... seems like that's always 
> a clue some typeclass could simplify it. Eventually I figured out
> 
> f k = join . fmap listToMaybe . M.lookup k

The 'Nothing -> Nothing' thing may also be a good hint that using the Maybe 
monad would be useful. Your function can also be defined as

   f k m = M.lookup k m >>= listToMaybe

-- 
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing


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

Message: 2
Date: Thu, 12 Nov 2015 10:17:09 +0100
From: Marcin Mrotek <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] figured out use for join!
Message-ID:
        <CAJcfPz=9sPwV=byfr4xpkbnaomj-mdl5yjgxgpa3y4upq9k...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello,

> using the Maybe monad would be useful.

But he already is? Anyway, `(x >>= f) == join (fmap f x)`

Best regards,
Marcin Mrotek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151112/4040e269/attachment-0001.html>

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

Message: 3
Date: Thu, 12 Nov 2015 10:38:22 +0100
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] figured out use for join!
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed

On 2015-11-12 10:17, Marcin Mrotek wrote:
>> using the Maybe monad would be useful.
> 
> But he already is?

Yes, of course, sorry for the imprecision. I meant to write 'using bind as 
defined for the Maybe monad'.

-- 
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing


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

Message: 4
Date: Thu, 12 Nov 2015 03:45:24 -0800
From: Dennis Raddle <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] question about list processing
Message-ID:
        <CAKxLvorMvAk4gixYNjqw4D0jz=37=y_zzjez-6btpzej59j...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151112/697a7474/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 89, Issue 17
*****************************************

Reply via email to