Advanced Functional Prog.

back - up - cont


Parsing expressions

The repetition operator can also be extended to return a list of result:

let rec rep' p s = 
  match p s with
  | [(r,s')] -> match rep' p s' with
                | [(rs,s'')] -> [(r::rs,s'')]
                | _          -> [([r],s')]
  | _        -> [([],s)];;

let num = rep' dig;;
num "12";;

9 - 18