Hypercorrection

(* Codage de filter avec quelques fonctions standard *)

let fold_left f a l = aux a l where
	rec aux r l = match l with
		| [] -> r
		| h::t -> aux (f r h) t
;;

let filter00 p l = rev (fold_left (fun a x -> if snd x then fst x::a else a) [] (map2 (fun x y -> x, y) l (map p l)));;

filter00 (fun x -> x > 10) [1;3;11;4;12];;

(* Mais avec flatten, c'est quand même plus simple *)

let rec flatten l = match l with
	| [] -> []
	| h::t -> fold_left (fun x y -> y::x) (flatten t) (rev h)
;;

let filter0 p l = flatten (map (fun x -> if p x then [x] else []) l);;

filter0 (fun x -> x > 10) [1;3;11;4;12];;