[Haskell-beginners] Using symbolic values in the case expression

Ozgur Akgun ozgurakgun at gmail.com
Thu Nov 11 13:42:32 EST 2010


On 11 November 2010 17:03, C K Kashyap <ckkashyap at gmail.com> wrote:

> v1 = 1
> v2 = 2
>
> f x = case x of
>  v1 -> "One"
>  v2 -> "Two"
>

The closest I can thin is the following:

f x | x == v1 = "One"
    | x == v2 = "Two"

But, keep in mind, this is *not* the same thing. It requires Eq on x, and
you lose all the exhaustiveness/overlapping checks pattern matching
provides.

HTH,

-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20101111/76cfcf5b/attachment.html


More information about the Beginners mailing list