diff options
Diffstat (limited to 'discocaml/eval.ml')
-rw-r--r-- | discocaml/eval.ml | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/discocaml/eval.ml b/discocaml/eval.ml index 9c12003..f8f7dc2 100644 --- a/discocaml/eval.ml +++ b/discocaml/eval.ml @@ -38,6 +38,17 @@ let find_redex_cbv (ast : expr ast) : expr index option = let find_redex_cbn (ast : expr ast) : expr index option = find_redex_cbn_in ast ast.root -let reduce (ast : expr ast) (_i : expr index) : expr ast = +exception NotARedex of expr ast + +let reduce (ast : expr ast) (i : expr index) : expr ast = + let fail () = raise (NotARedex { ast with root = i }) in let ast = copy ast in + let must_int j = match get_subexpr ast j with Int n -> n | _ -> fail () in + Arraylist.set ast.subexprs i.index + (match get_subexpr ast i with + | App (_f, _x) -> failwith "TODO" + | Prim (Add, (l, r)) -> Int (must_int l + must_int r) + | Prim (Sub, (l, r)) -> Int (must_int l - must_int r) + | Prim (Mul, (l, r)) -> Int (must_int l * must_int r) + | _ -> fail ()); ast |