Lambda case expressions

The LambdaCase GHC extension introduces a kind of expression that is something of a cross between a case expression and a lambda. It’s been in GHC since 7.6.1.

For example, take this function that converts the l characters in a string to Greek.

lambdaize = fmap f
    f 'l' = 'λ'
    f x   = x
λ> putStrLn (lambdaize "Delightful!")
-- Deλightfuλ!

We can write this function more tersely by converting the named function f into a lambda-case expression:

{-# LANGUAGE LambdaCase #-}

lambdaize = fmap (\case 'l' -> 'λ'
                        x   -> x)

Join Type Classes for courses and projects to get you started and make you an expert in FP with Haskell.