From f74dd82111c0f50fc7b1a222c796d258e82281fb Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 22 Nov 2017 11:19:41 +0100 Subject: Resolve run-time error for functions that use arguments twice further down the expression graph --- pf.icl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'pf.icl') 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 -- cgit v1.2.3