Dieter Wick
Dieter Wick

Reputation: 11

Case - why am i getting illegal lambda expression

 data Nat = Zero | Succ Nat 
 data NatSig val = NatSig {zero_ :: val, succ :: val -> val}

foldNat :: NatSig val -> Nat -> val

foldNat alg = \case Zero -> zero_ alg 
                    Succ n -> succ alg $ foldNat alg sn

Hello this is a code from my University but if i want to run it i get an error

Illegal lambda-case (use -XLambdaCase)

some one know why?

Upvotes: 1

Views: 1252

Answers (1)

The syntax \case isn't in the Haskell Report, so it isn't allowed in standard Haskell. To use it, you have to enable the LambdaCase extension. There are several different ways you can do so, including:

  1. Put -XLambdaCase on the command line
  2. Put {-# LANGUAGE LambdaCase #-} at the top of the file
  3. Run :set -XLambdaCase at the GHCi prompt

Upvotes: 9

Related Questions