open Pcaml;; EXTEND GLOBAL: expr; expr: [ [ "map"; list = expr; "with"; OPT "|"; clauses = LIST1 clause SEP "|" -> <:expr< List.map (fun [ $list:clauses$ ]) $list$ >> ] | [ "iterate"; list = expr; "with"; OPT "|"; clauses = LIST1 clause SEP "|" -> <:expr< List.iter (fun [ $list:clauses$ ]) $list$ >> ] | [ "foldr"; list = expr; "from"; initval = expr; "with"; OPT "|"; clauses = LIST1 clause SEP "|" -> <:expr< List.fold_right (fun a b -> match (a, b) with [ $list:clauses$ ]) $list$ $initval$ >> ] | [ "foldl"; list = expr; "from"; initval = expr; "with"; OPT "|"; clauses = LIST1 clause SEP "|" -> <:expr< List.fold_left (fun a b -> match (a, b) with [ $list:clauses$ ]) $initval$ $list$ >> ] ]; clause: [[ p = patt; w = OPT when_expr; "->"; e = expr -> (p, w, e)]]; when_expr: [[ "when"; e = expr -> e ]]; END;;