aboutsummaryrefslogtreecommitdiff
path: root/pf.icl
diff options
context:
space:
mode:
Diffstat (limited to 'pf.icl')
-rw-r--r--pf.icl12
1 files changed, 6 insertions, 6 deletions
diff --git a/pf.icl b/pf.icl
index 7e0f76f..46016e1 100644
--- a/pf.icl
+++ b/pf.icl
@@ -134,20 +134,20 @@ optim (Lambda id e)
| otherwise = Ident "const" @ optim e
where
optApp :: Expr -> Expr
- optApp (f @ x)
- | hasIdent id f && hasIdent id x = Ident "ap" @ Lambda id f @ Lambda id x
- | otherwise = case moveOutside id (f @ x) of
+ optApp (f @ x) = case moveOutside id (f @ x) of
a=:(f @ Ident id`) -> if (id == id`) f (Ident "const" @ a)
a -> Ident "const" @ a
-optim (Ident "flip" @ Ident "ap" @ Ident "id") = Ident "join"
-optim (f @ x) = optim f @ optim x
+optim (f @ x) = case optim f @ optim x of
+ Ident "flip" @ Ident "ap" @ Ident "id" -> Ident "join"
+ Ident "ap" @ f @ Ident "id" -> Ident "join" @ f
+ e -> e
optim e = e
moveOutside :: Ident Expr -> Expr
moveOutside _ (Ident id) = Ident id
moveOutside _ (Literal l) = Literal l
moveOutside id (f @ x)
-| hasIdent id f && hasIdent id x = abort "moveOutside on @ with id in both sides"
+| hasIdent id f && hasIdent id x = Ident "ap" @ Lambda id f @ Lambda id x @ Ident id
| hasIdent id f = case moveOutside id f of
Ident id -> Ident "flip" @ Ident "id" @ x @ Ident id
g @ Ident id -> Ident "flip" @ g @ x @ Ident id