Skip to content

Instantly share code, notes, and snippets.

@rctay
Last active December 26, 2015 08:39
Show Gist options
  • Save rctay/7124011 to your computer and use it in GitHub Desktop.
Save rctay/7124011 to your computer and use it in GitHub Desktop.
fixed-point (pseudo) evaluation
let eval_stable n one_step x : lambda * int =
let ctr = new Gen.counter 0 in
let tick () = ctr # inc in
let step = one_step tick in
let rec aux x prev =
let curr = ctr # get in
if prev = curr then
x
else if ctr#get > n then (
print_endline ("exceeded "^(string_of_int n)^" reductions");
x
)
else
(* if we encounter a let, fudge curr to allow one more run of step *)
let curr =
if match x with |Let _ -> true | _ -> false
then curr-1
else curr in
aux (step x) curr in
(* start with -1 so we run step at least once *)
let r=aux x (ctr#get - 1) in
(r,ctr#get);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment