X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/e9f528ab975ac28c16b2c370e69206a48f584d78..95f148cdfa509a961a5610ca274e29ba238561e3:/src/reduce.sml diff --git a/src/reduce.sml b/src/reduce.sml index 525d713..9e538d6 100644 --- a/src/reduce.sml +++ b/src/reduce.sml @@ -42,6 +42,8 @@ fun freeIn x (b, _) = | EWith (e1, e2) => freeIn x e1 orelse freeIn x e2 | EALam (x', _, b') => x <> x' andalso freeIn x b' + | EIf (e1, e2, e3) => freeIn x e1 orelse freeIn x e2 orelse freeIn x e3 + local val freshCount = ref 0 in @@ -106,6 +108,8 @@ fun subst x e (bAll as (b, loc)) = else (EALam (x', p, subst x e b'), loc) + | EIf (b1, b2, b3) => (EIf (subst x e b1, subst x e b2, subst x e b3), loc) + fun findPrim (e, _) = case e of EApp (f, x) => @@ -179,4 +183,16 @@ fun reduceExp G (eAll as (e, loc)) = (EALam (x, p, reduceExp G' e), loc) end + | EIf (e1, e2, e3) => + let + val e1' = reduceExp G e1 + fun e2' () = reduceExp G e2 + fun e3' () = reduceExp G e3 + in + case e1' of + (EVar "true", _) => e2' () + | (EVar "false", _) => e3' () + | _ => (EIf (e1', e2' (), e3' ()), loc) + end + end