1 2 3 4 5 6 7 8 9 10 11 12 13 14 | type 'a t = 'a list let empty = [] (* exceptions *) exception UnboundVariable (* offset : string -> xs -> int *) let offset x xs = let rec loop xs n = match xs with [] -> raise UnboundVariable | first :: rest -> if x = first then n else loop rest (n + 1) in loop xs 0 |