aboutsummaryrefslogtreecommitdiff
path: root/discocaml
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-01-19 20:00:04 -0600
committerNathan Ringo <nathan@remexre.com>2024-01-19 20:00:04 -0600
commit65b6e9cec4a75e783dd1e1d01e4af9e558d9bf38 (patch)
treecbb37c81bed2bed9ed4de8d228a3d88d17c822e0 /discocaml
parented686f7c7fdce0c3062a2859e32e974c096246df (diff)
Call by value.
Diffstat (limited to 'discocaml')
-rw-r--r--discocaml/eval.ml15
1 files changed, 13 insertions, 2 deletions
diff --git a/discocaml/eval.ml b/discocaml/eval.ml
index f8f7dc2..a5cfe41 100644
--- a/discocaml/eval.ml
+++ b/discocaml/eval.ml
@@ -15,8 +15,19 @@ let is_redex (ast : expr ast) (i : expr index) : bool =
| _ -> false)
| Var _ -> false
-let find_redex_cbv_in (_ast : expr ast) (_i : expr index) : expr index option =
- None
+let find_redex_cbv_in (ast : expr ast) : expr index -> expr index option =
+ let rec loop (i : expr index) : expr index option =
+ or_else
+ (match get_subexpr ast i with
+ | App (f, x) -> or_else (loop f) (lazy (loop x))
+ | Int _ -> None
+ | Lam (_, _) -> None
+ | Prim (Add, (l, r)) | Prim (Sub, (l, r)) | Prim (Mul, (l, r)) ->
+ or_else (loop l) (lazy (loop r))
+ | Var _ -> None)
+ (lazy (if is_redex ast i then Some i else None))
+ in
+ loop
let find_redex_cbn_in (ast : expr ast) : expr index -> expr index option =
let rec loop (i : expr index) : expr index option =