Advanced Functional Prog.

back - up - cont


Parsing expressions

Next, we have to define sequential composition - i.e check first letter then next letter for instance:

let thn p1 p2 (s:string) = 
  match p1 s with
  | [(r,s')] -> p2 s' 
  | _        -> [];;

let (&&) = thn;;

((sym 'h') && (sym 'e') && (sym 'l')) "hello";;

Nb. The code illustrates again the capability of the language to use binary function (thn) as infix operators (&&).


3 - 18