From b0b562e5000dbcac8b944801e7ab96556855a4ff Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 25 May 2025 23:34:51 +0200 Subject: Print EMaybe as case --- src/AST/Pretty.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/AST/Pretty.hs b/src/AST/Pretty.hs index 2bb78d4..6d70ca3 100644 --- a/src/AST/Pretty.hs +++ b/src/AST/Pretty.hs @@ -145,12 +145,20 @@ ppExpr' d val expr = case expr of EMaybe _ a b e -> do let STMaybe t = typeOf e - a' <- ppExpr' 11 val a + e' <- ppExpr' 0 val e + a' <- ppExpr' 0 val a name <- genNameIfUsedIn t IZ b b' <- ppExpr' 0 (Const name `SCons` val) b - e' <- ppExpr' 11 val e - return $ ppParen (d > 10) $ - ppApp (ppString "maybe" <> ppX expr) [a', ppLam [ppString name] b', e'] + return $ ppParen (d > 0) $ + align $ + group (flatAlt + (annotate AKey (ppString "case") <> ppX expr <+> e' + <> hardline <> annotate AKey (ppString "of")) + (annotate AKey (ppString "case") <> ppX expr <+> e' <+> annotate AKey (ppString "of"))) + <> hardline + <> indent 2 + (ppString "Nothing" <+> ppString "->" <+> a' + <> hardline <> ppString "Just" <+> ppString name <+> ppString "->" <+> b') ELNil _ _ _ -> return (ppString "LNil") -- cgit v1.2.3-70-g09d2