879 B
879 B
Полезные комбинаторы
Код из книги
#let mem x l = exists (fun y -> y = x) l;;
mem : ’a -> ’a list -> bool = <fun>
#let insert x l =
if mem x l then l else x::l;;
insert : ’a -> ’a list -> ’a list = <fun>
#let union l1 l2 = itlist insert l1 l2;;
union : ’a list -> ’a list -> ’a list = <fun>
#let setify l = union l [];;
setify : ’a list -> ’a list = <fun>
#let Union l = itlist union l [];;
Union : ’a list list -> ’a list = <fun>
#let intersect l1 l2 = filter (fun x -> mem x l2) l1;;
intersect : ’a list -> ’a list -> ’a list = <fun>
#let subtract l1 l2 = filter (fun x -> not mem x l2) l1;;
subtract : ’a list -> ’a list -> ’a list = <fun>
#let subset l1 l2 = forall (fun t -> mem t l2) l1;;
subset : ’a list -> ’a list -> bool = <fun>