summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/AST/Count.hs3
-rw-r--r--src/AST/Pretty.hs15
-rw-r--r--src/Simplify.hs9
3 files changed, 27 insertions, 0 deletions
diff --git a/src/AST/Count.hs b/src/AST/Count.hs
index 40a46f6..ad68685 100644
--- a/src/AST/Count.hs
+++ b/src/AST/Count.hs
@@ -110,6 +110,9 @@ occCountGeneral onehot unpush alter many = go WId
EInl _ _ e -> re e
EInr _ _ e -> re e
ECase _ e a b -> re e <> (re1 a `alter` re1 b)
+ ENothing _ _ -> mempty
+ EJust _ e -> re e
+ EMaybe _ a b e -> re a <> re1 b <> re e
EConstArr{} -> mempty
EBuild1 _ a b -> re a <> many (re1 b)
EBuild _ _ a b -> re a <> many (re1 b)
diff --git a/src/AST/Pretty.hs b/src/AST/Pretty.hs
index f5e681a..7f60db1 100644
--- a/src/AST/Pretty.hs
+++ b/src/AST/Pretty.hs
@@ -92,6 +92,21 @@ ppExpr' d val = \case
showString "case " . e' . showString (" of { Inl " ++ name1 ++ " -> ") . a'
. showString (" ; Inr " ++ name2 ++ " -> ") . b' . showString " }"
+ ENothing _ _ -> return $ showString "nothing"
+
+ EJust _ e -> do
+ e' <- ppExpr' 11 val e
+ return $ showParen (d > 10) $ showString "Just " . e'
+
+ EMaybe _ a b e -> do
+ let STMaybe t = typeOf e
+ a' <- ppExpr' 11 val a
+ name <- genNameIfUsedIn t IZ b
+ b' <- ppExpr' 11 (Const name `SCons` val) b
+ e' <- ppExpr' 11 val e
+ return $ showParen (d > 10) $
+ showString "maybe " . a' . showString " " . b' . showString " " . e'
+
EConstArr _ _ ty v
| Dict <- scalRepIsShow ty -> return $ showsPrec d v
diff --git a/src/Simplify.hs b/src/Simplify.hs
index 3ac68ed..2007585 100644
--- a/src/Simplify.hs
+++ b/src/Simplify.hs
@@ -66,6 +66,8 @@ simplify' = \case
-- TODO: array indexing (index of build, index of fold)
+ -- TODO: beta rules for maybe
+
-- TODO: constant folding for operations
-- TODO: accum of zero, plus of zero
@@ -79,6 +81,9 @@ simplify' = \case
EInl _ t e -> EInl ext t (simplify' e)
EInr _ t e -> EInr ext t (simplify' e)
ECase _ e a b -> ECase ext (simplify' e) (simplify' a) (simplify' b)
+ ENothing _ t -> ENothing ext t
+ EJust _ e -> EJust ext (simplify' e)
+ EMaybe _ a b e -> EMaybe ext (simplify' a) (simplify' b) (simplify' e)
EConstArr _ n t v -> EConstArr ext n t v
EBuild1 _ a b -> EBuild1 ext (simplify' a) (simplify' b)
EBuild _ n a b -> EBuild ext n (simplify' a) (simplify' b)
@@ -118,6 +123,9 @@ hasAdds = \case
EInl _ _ e -> hasAdds e
EInr _ _ e -> hasAdds e
ECase _ e a b -> hasAdds e || hasAdds a || hasAdds b
+ ENothing _ _ -> False
+ EJust _ e -> hasAdds e
+ EMaybe _ a b e -> hasAdds a || hasAdds b || hasAdds e
EConstArr _ _ _ _ -> False
EBuild1 _ a b -> hasAdds a || hasAdds b
EBuild _ _ a b -> hasAdds a || hasAdds b
@@ -145,6 +153,7 @@ checkAccumInScope = \case SNil -> False
check STNil = False
check (STPair s t) = check s || check t
check (STEither s t) = check s || check t
+ check (STMaybe t) = check t
check (STArr _ t) = check t
check (STScal _) = False
check STAccum{} = True