1 let filter p l = 2 let rec filter_int g ll rr = 3 match ll with 4 | [] -> rr 5 | h::r -> if (g h) then filter_int g r (h::rr) else filter_int g r rr 6 in 7 let rec map_int g ll rr = 8 match ll with 9 | [] -> rr 10 | h::r -> map_int g r ((g h)::rr) 11 in 12 map_int (fun i -> i) (filter_int p l []) [] ;;
实现的功能如下,给定一个判别函数p,对列表list的每个元素,如果p执行为真,则输出到结果列表中。