playground/sml/inf.sml

43 lines
884 B
Standard ML

(* Attempt to replicate a coq file *)
datatype instr
= Const of bool
| Goto of int
type prog = instr list
fun eclosure_aux p idx visited =
let
val inds = List.tabulate (length p, fn x=>x)
val aug = ListPair.zip (inds, p)
in
case (List.nth (aug, idx)) of
(i, x) =>
(case x of
Const _ => [i]
| Goto k =>
if List.exists (fn x => x=k) visited then [i]
else i :: (eclosure_aux p k (i::visited)))
end
fun eclosure p idx = eclosure_aux p idx []
val p1 = [
Const true, (* 0 *)
Const false, (* 1 *)
Goto 4, (* 2 *)
Const true, (* 3 *)
Goto 1 (* 4 *)
]
val p2 = [
Const true, (* 0 *)
Const false, (* 1 *)
Goto 4, (* 2 *)
Const true, (* 3 *)
Goto 2 (* 4 *)
]
val v1 = eclosure p1 2
(* [2,4,1] : int list *)
val v2 = eclosure p2 2