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

Thomas Davie tom.davie at gmail.com
Thu Nov 11 12:06:06 EST 2010


On 11 Nov 2010, at 17:03, C K Kashyap wrote:

> Hi,
> I'd like to do something like this -
> 
> Instead of doing this -
> 
> f x = case x of
>   1 -> "One"
>   2 -> "Two"
> 
> I'd like to do this -
> 
> v1 = 1
> v2 = 2
> 
> f x = case of
>  v1 -> "One"
>  v2 -> "Two"
> 
> 
> Is that possible?

Pattern matching against expressions is not possible, except in the very very limited case of n + k patterns, so no.

Bob


More information about the Beginners mailing list