Skip to content

Commit d02c9a9

Browse files
committed
Add support for LambdaCase
1 parent c73ce56 commit d02c9a9

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/Fay/Compiler/Desugar.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ desugar emptyAnnotation md = runDesugar emptyAnnotation $
6767
>>= desugarTupleSection
6868
>>= desugarImplicitPrelude
6969
>>= desugarFFITypeSigs
70+
>>= desugarLCase
7071

7172
-- | Desugaring
7273

@@ -129,6 +130,12 @@ desugarTupleCon = transformBi $ \ex -> case ex of
129130
body = Tuple l b (Var l . UnQual l <$> names)
130131
_ -> Nothing
131132

133+
-- | \case x of [...] -> \foo -> case foo of [...]
134+
desugarLCase :: (Data l, Typeable l) => Module l -> Desugar l (Module l)
135+
desugarLCase = transformBiM $ \ex -> case ex of
136+
LCase l alts -> withScopedTmpName l $ \n -> return $ Lambda l [PVar l n] (Case l (Var l (UnQual l n)) alts)
137+
_ -> return ex
138+
132139
desugarTupleSection :: (Data l, Typeable l) => Module l -> Desugar l (Module l)
133140
desugarTupleSection = transformBiM $ \ex -> case ex of
134141
TupleSection l _ mes -> do

src/Fay/Compiler/Misc.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ defaultExtensions = map EnableExtension
332332
,GADTs
333333
,ImplicitPrelude
334334
,KindSignatures
335+
,LambdaCase
335336
,NamedFieldPuns
336337
,PackageImports
337338
,RecordWildCards

tests/LambdaCase.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{-# LANGUAGE LambdaCase #-}
2+
module LambdaCase where
3+
4+
f :: Int -> Bool
5+
f = \case
6+
2 -> True
7+
_ -> False
8+
9+
main :: Fay ()
10+
main = do
11+
print (f 2)

tests/LambdaCase.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true

0 commit comments

Comments
 (0)