Skip to content

Commit b0cd9d6

Browse files
committed
Converter: Convert do-notation
1 parent cba6878 commit b0cd9d6

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Axel/Haskell/Convert.hs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,28 @@ instance ToExpr HSE.Exp where
365365
toExpr (HSE.Case _ expr matches) =
366366
AST.ECaseBlock $
367367
AST.CaseBlock Nothing (toExpr expr) (map altToClause matches)
368-
toExpr expr@HSE.Do {} = unsupportedExpr expr
368+
toExpr (HSE.Do _ stmts) =
369+
AST.EFunctionApplication $
370+
AST.FunctionApplication
371+
Nothing
372+
(AST.EIdentifier Nothing "do'")
373+
(map handleStmt stmts)
374+
where
375+
handleStmt (HSE.Generator _ pat expr) =
376+
AST.EFunctionApplication $
377+
AST.FunctionApplication
378+
Nothing
379+
(AST.EIdentifier Nothing "<-")
380+
[toExpr pat, toExpr expr]
381+
handleStmt (HSE.Qualifier _ expr) = toExpr expr
382+
handleStmt (HSE.LetStmt _ binds) =
383+
AST.EFunctionApplication $
384+
AST.FunctionApplication
385+
Nothing
386+
(AST.EIdentifier Nothing "let")
387+
(map handleClause $ bindsToClauses binds)
388+
handleClause (var, val) =
389+
AST.EFunctionApplication $ AST.FunctionApplication Nothing var [val]
369390
toExpr expr@HSE.MDo {} = unsupportedExpr expr
370391
toExpr (HSE.Tuple _ _ exps) =
371392
AST.EFunctionApplication $

0 commit comments

Comments
 (0)