[Haskell-cafe] Question on "case x of g" when g is a function
Hamilton Richards
ham at cs.utexas.edu
Thu Jan 27 14:37:48 EST 2005
If he really wanted to use a case-expression, he could write it this way:
> f x = case x of
> False -> 0
> True -> 1
--Ham
At 1:02 PM +0100 2005/1/27, Henning Thielemann wrote:
>On Thu, 27 Jan 2005 yeoh at cs.wisc.edu wrote:
>
>> Can a kind soul please enlighten me on why f bit0 and f bit1
>> both return 0?
>>
>> > bit0 = False
>> > bit1 = True
>> > f x = case x of
>> > bit0 -> 0
>> > bit1 -> 1
>
>If you compile with 'ghc -Wall' GHC should report that the identifier
>'bit0' in the case expression shadows the global 'bit0' identifier. What
>you want to do is:
>
>f x = if x == bit0 then 0 else 1
>
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list