Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Desugar list comprehension (mike h)


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

Message: 1
Date: Wed, 2 Dec 2020 10:30:37 +0000
From: mike h <mike_k_hough...@yahoo.co.uk>
To: beginners@haskell.org
Subject: [Haskell-beginners] Desugar list comprehension
Message-ID: <84d90b6c-8c1f-4eab-a573-38d1e3388...@yahoo.co.uk>
Content-Type: text/plain; charset="utf-8"

Hi,
 I have 
sumIs2020P1' xs = do 
    x <- xs
    y <- xs
    guard (x + y == 2020)
    pure (x,y)

which has been desugared from a list comprehension
I would like to reduce this even more using >>= 
So I do
sumIs2020P1'' xs =  (a,b) where
    (a,b):rest = filter (\(x,y) -> x + y == 2020)  pairs       

    pairs = xs >>= \x -> 
                    xs >>= \y -> 
                        pure (x,y)

but really I would like the guard to be within the >>= sections but I could not 
work out 
how to do it!
i.e. I’m looking for something like (pseudo code)

pairs = xs >>= \x -> 
                    xs >>= \y -> 
                        if (x + y == 2020) then pure (x,y) else DO_NOTHING
                        
which would then allow the filter to be removed. 


Many Thanks

Mike



Dr Mike Houghton

mike_k_hough...@yahoo.co.uk



-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20201202/bf9fb94f/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 149, Issue 1
*****************************************

Reply via email to