(* sum : int list -> int *) let rec sum is = match is with | [] -> 0 | i::is -> i + sum is (* sum' : int list -> int ---- the tail-call/accumulator version *) let sum' is = let rec visit is acc = match is with | [] -> acc | i::is -> visit is (i + acc) in visit is 0 (* append : 'a list -> 'a list -> 'a list *) let rec append xs ys = match xs with | [] -> ys | x::xs -> x :: (append xs ys) type inst = | Push of int | Add | Mult (* instructions_to_string : inst list -> string *) let rec instructions_to_string is = let i2s i = match i with | Push n -> "push " ^ (string_of_int n) ^ "; " | Add -> "add; " | Mult -> "mult; " in match is with | [] -> "" | i::is-> let svi = i2s i in let svis = instructions_to_string is in svi ^ svis