How to include {-# LANGUAGE LambdaCase #-} at the ghci prompt

I've got this code I've entered into the ghci by hand between :{ and :} :{ {-# LANGUAGE LambdaCase #-} data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show) infixr 5 `Cons` subst_c :: (a -> Bool) -> (a, MyList a) -> MyList a subst_c pred = \ case (_, Empty) -> Empty (n, Cons e t) | pred e -> Cons n $ subst_c pred (n, t) | otherwise -> Cons e $ subst_c pred (n, t) :} but I keep getting the error Illegal lambda-case (use -XLambdaCase) This works fine inside an .hs file and :load and run at the prompt. However, I'm using Emacs org-mode and need to keep everything limited to a version of hand-entered :{ ... :}. Any suggestions? LB

Il 26 marzo 2021 alle 12:20 Galaxy Being ha scritto:
I've got this code I've entered into the ghci by hand between :{ and :}
:{ {-# LANGUAGE LambdaCase #-} data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show) infixr 5 `Cons`
subst_c :: (a -> Bool) -> (a, MyList a) -> MyList a subst_c pred = \ case (_, Empty) -> Empty (n, Cons e t) | pred e -> Cons n $ subst_c pred (n, t) | otherwise -> Cons e $ subst_c pred (n, t) :}
λ> :set -XLambdaCase

Exactly. Thanks.
On Fri, Mar 26, 2021 at 12:33 PM Francesco Ariis
Il 26 marzo 2021 alle 12:20 Galaxy Being ha scritto:
I've got this code I've entered into the ghci by hand between :{ and :}
:{ {-# LANGUAGE LambdaCase #-} data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show) infixr 5 `Cons`
subst_c :: (a -> Bool) -> (a, MyList a) -> MyList a subst_c pred = \ case (_, Empty) -> Empty (n, Cons e t) | pred e -> Cons n $ subst_c pred (n, t) | otherwise -> Cons e $ subst_c pred (n, t) :}
λ> :set -XLambdaCase _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On Fri, Mar 26, 2021 at 06:31:53PM +0100, Francesco Ariis wrote:
Il 26 marzo 2021 alle 12:20 Galaxy Being ha scritto:
I've got this code I've entered into the ghci by hand between :{ and :}
:{ {-# LANGUAGE LambdaCase #-} data List a = Empty | Cons a (List a) deriving (Eq, Ord, Show) infixr 5 `Cons`
subst_c :: (a -> Bool) -> (a, MyList a) -> MyList a subst_c pred = \ case (_, Empty) -> Empty (n, Cons e t) | pred e -> Cons n $ subst_c pred (n, t) | otherwise -> Cons e $ subst_c pred (n, t) :}
λ> :set -XLambdaCase
You can also start GHCi with it: $ ghci -XLambdaCase Tom
participants (3)
-
amindfv@mailbox.org
-
Francesco Ariis
-
Galaxy Being