Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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:  combine expressions in do block (Brent Yorgey)


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

Message: 1
Date: Wed, 8 Jan 2014 15:31:05 -0500
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] combine expressions in do block
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Wed, Jan 08, 2014 at 09:21:59AM +0100, Daniel Trstenjak wrote:
> 
> Hi Renah,
> 
> On Wed, Jan 08, 2014 at 10:09:18AM +0200, Renah Scarowsky wrote:
> > How can I combine these two cases together (or otherwise simplify the code)?
> 
> I don't know if I'm understanding you correctly, but something like this?
> 
> f a = do
>    case g a of
>       Nothing -> return ()
>       Just b -> do
>          h a (field1 b) (field2 b)
>          i a (j a) (field1 b) (field2 b)

To take this a step further, if 'field1' and 'field2' are projections,
then you might be able to replace them with pattern-matching as well:

f a = do
  case g a of
    Nothing -> return ()
    Just (Constructor f1 f2) -> do
      h a f1 f2
      i a (j a) f1 f2

I know this is just a made-up example and not real code, but figured
it was worth mentioning anyway.

-Brent


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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 67, Issue 14
*****************************************

Reply via email to