else
(EALam (x', p, subst x e b'), loc)
+fun findPrim (e, _) =
+ case e of
+ EApp (f, x) =>
+ (case findPrim f of
+ NONE => NONE
+ | SOME (f, xs) => SOME (f, xs @ [x]))
+ | EVar x => SOME (x, [])
+ | _ => NONE
+
fun reduceExp G (eAll as (e, loc)) =
case e of
EInt _ => eAll
in
case e1' of
(ELam (x, _, b), _) => reduceExp G (subst x e2' b)
- | _ => (EApp (e1', e2'), loc)
+ | _ =>
+ case findPrim eAll of
+ NONE => (EApp (e1', e2'), loc)
+ | SOME (f, args) =>
+ case function f of
+ NONE => (EApp (e1', e2'), loc)
+ | SOME f => case f (map (reduceExp G) args) of
+ NONE => (EApp (e1', e2'), loc)
+ | SOME e' => reduceExp G e'
end
| ESkip => eAll