[Haskell-beginners] Case statements shorter
Ozgur Akgun
ozgurakgun at gmail.com
Mon Nov 1 12:25:07 EDT 2010
No, not if you use case. But you can do better with a simple if, in this
particular case.
if n == 3 || n == 4
then "Something"
else "Other"
Or even,
if n `elem` [3,4]
them "Something"
else "Other"
HTH,
On 1 November 2010 15:59, Angel Alonso <alderzdev at gmail.com> wrote:
> Hi,
>
> I have the following piece of code:
>
> n = 3
> case n of
> 3 -> "Something"
> 4 -> "Something"
> _ -> "Other"
>
> Is it possible to shorten the case statement into something like this?:
>
> n = 3
> case n of
> 3 or 4 -> "Something"
> _ -> "Other"
>
> Thanks.
>
> -- Angel Alonso
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20101101/45040dfe/attachment.html
More information about the Beginners
mailing list