[Haskell-cafe] pattern matching vs if-then-else

Gregory Collins greg at gregorycollins.net
Sun Aug 12 15:05:28 CEST 2012


On Sun, Aug 12, 2012 at 1:30 PM, Maarten Faddegon <
haskell-cafe at maartenfaddegon.nl> wrote:
>
>         = if    -- All stmts use the same lcv
>                    test_lcv == init_lcv
> && test_lcv == update_lcv
> && test_lcv == update_lcv'
>                 -- And the lcv is not updated in the body
>

This part of the conditional can be written more succinctly as:

all (== test_lcv) [init_lcv, update_lcv, update_lcv']


Re: the if statement, you can also use guard syntax.

G
-- 
Gregory Collins <greg at gregorycollins.net>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120812/2ad658e0/attachment.htm>


More information about the Haskell-Cafe mailing list