(** This module gives lists with internal binders. *) type ('a, 'b) t = | BNil | BCons of 'a * ('a, 'b) t | BNew of ('b -> ('a, 'b) t) let (^::) x l = BCons (x, l) let rec (^@) l1 l2 = match l1 with | BNil -> l2 | BCons (x, l1') -> BCons (x, l1' ^@ l2) | BNew f -> BNew (fun x -> f x ^@ l2) let (?^) f = BNew f let b_rev l = let rec rev_acc acc = function | BNil -> acc | BCons (x, l) -> rev_acc (BCons (x, acc)) l | BNew f -> BNew (fun x -> rev_acc acc (f x)) in rev_acc BNil l