Re: how to get an IntSet and a FloatSet with batteries
Florent Monnier <[email protected]>
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAE1DttDiqJc9gWF6TzCGbkfcekJLB8mw55hBaEnwVmdc707CiA@mail.gmail.com> |
On 2014/01/06, Florent Monnier answered to:
> Francois Berenger, who wrote on 2014/01/06:
[...]
>> Additional bonus points: how to add the functions of_list and to_list to
>> those sets?
>>
>> to_list should be an alias for elements
[...]
> if my boss
or teacher
> would request me to produce some strongly
> copylefted code I would probably do something like:
$ ocaml nums.cma str.cma unix.cma bigarray.cma -I +batteries batteries.cma
OCaml version 4.01.0
# module IntSet = Set.Make(BatInt) ;;
# module IntSet = struct include IntSet let to_list = elements
let of_list lst = List.fold_left (fun set elm -> IntSet.add elm set)
IntSet.empty lst
end ;;
# let l1 = IntSet.of_list [1;2;3;4] ;;
val l1 : IntSet.t = <abstr>
# let l2 = IntSet.of_list [2;3;4;5] ;;
val l2 : IntSet.t = <abstr>
# let l3 = IntSet.inter l1 l2 ;;
val l3 : IntSet.t = <abstr>
# IntSet.to_list l3 ;;
- : IntSet.elt list = [2; 3; 4]
It seems to produce the expected results, but further investigations
would probably be required in order to reach certitudes.
--
Florent