Advanced Functional Prog.

back - up - cont


Parsing expressions

The previous code can be improved to return numbers rather than list of digits:

let rec eval (xs:char list) = 
  match xs with
  | [x]    -> (int x)-48
  | x::xs' -> 10*((int x)-48) + (eval xs');;

let ret v s = [(v,s)];;
let fail  s = [];;

let num' = num && fun v -> if not (v=[]) then ret (eval v) else fail;;
num' "12";;

10 - 18