X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Fski_evaluator.ml;h=15ee4a7766818dc84a551648da8b016897fd5da7;hp=4d6f9a122aef7da22ab444970690c03f7bc9f6e7;hb=7ea03edf218ad5b63cd7ee0faa33391e1f3893ae;hpb=b15a6b392f7989734f899fc9efcb211f95d2f416;ds=sidebyside diff --git a/code/ski_evaluator.ml b/code/ski_evaluator.ml index 4d6f9a12..15ee4a77 100644 --- a/code/ski_evaluator.ml +++ b/code/ski_evaluator.ml @@ -1,30 +1,32 @@ -type term = I | S | K | App of (term * term) - -let skomega = App (App (App (S,I), I), App (App (S,I), I)) +type term = I | S | K | App of (term * term) + +let skomega = App (App (App (S,I), I), App (App (S,I), I)) let test = App (App (K,I), skomega) - -let reduce_one_step (t:term):term = match t with - App(I,a) -> a - | App(App(K,a),b) -> a - | App(App(App(S,a),b),c) -> App(App(a,c),App(b,c)) - | _ -> t - -let is_redex (t:term):bool = not (t = reduce_one_step t) - -let rec reduce (t:term):term = match t with - I -> I - | K -> K - | S -> S - | App (a, b) -> - let t' = App (reduce a, reduce b) in - if (is_redex t') then reduce (reduce_one_step t') - else t' -let rec reduce_lazy (t:term):term = match t with - I -> I - | K -> K - | S -> S - | App (a, b) -> - let t' = App (reduce_lazy a, b) in - if (is_redex t') then reduce_lazy (reduce_one_step t') - else t' +let reduce_if_redex (t:term):term = match t with + | App(I,a) -> a + | App(App(K,a),b) -> a + | App(App(App(S,a),b),c) -> App(App(a,c),App(b,c)) + | _ -> t + +let is_redex (t:term):bool = not (t = reduce_if_redex t) + +let rec reduce_try2 (t:term):term = match t with + | I -> I + | K -> K + | S -> S + | App (a, b) -> + let t' = App (reduce_try2 a, reduce_try2 b) in + if (is_redex t') then let t'' = reduce_if_redex t' + in reduce_try2 t'' + else t' + +let rec reduce_lazy (t:term):term = match t with + | I -> I + | K -> K + | S -> S + | App (a, b) -> + let t' = App (reduce_lazy a, b) in + if (is_redex t') then let t'' = reduce_if_redex t' + in reduce_lazt t'' + else t'