diff --git a/.ocamlinit b/.ocamlinit index 4022f3d2..fd2fad85 100644 --- a/.ocamlinit +++ b/.ocamlinit @@ -6,4 +6,4 @@ #load "containers.cma";; #require "threads";; #load "thread_containers.cma";; -open Enum.Infix;; +open Gen.Infix;; diff --git a/examples/collatz.ml b/examples/collatz.ml index 47b78aea..f792527f 100644 --- a/examples/collatz.ml +++ b/examples/collatz.ml @@ -10,7 +10,7 @@ let collatz n filename = Format.printf "print graph to %s@." filename; let out = open_out filename in let fmt = Format.formatter_of_out_channel out in - LazyGraph.Dot.pp ~name:"collatz" g fmt (Enum.singleton n); + LazyGraph.Dot.pp ~name:"collatz" g fmt (Gen.singleton n); Format.pp_print_flush fmt (); close_out out diff --git a/examples/mem_size.ml b/examples/mem_size.ml index 618d851f..1a54d91c 100644 --- a/examples/mem_size.ml +++ b/examples/mem_size.ml @@ -1,17 +1,17 @@ (** Compute the memory footprint of a value (and its subvalues). Reference is http://rwmj.wordpress.com/2009/08/05/ocaml-internals-part-2-strings-and-other-types/ *) -open Enum.Infix +open Gen.Infix (** A graph vertex is an Obj.t value *) let graph = let force x = if Obj.is_block x then - let children = Enum.map (fun i -> i, Obj.field x i) (0--(Obj.size x - 1)) in + let children = Gen.map (fun i -> i, Obj.field x i) (0--(Obj.size x - 1)) in LazyGraph.Node (x, Obj.tag x, children) else - LazyGraph.Node (x, Obj.obj x, Enum.empty) + LazyGraph.Node (x, Obj.obj x, Gen.empty) in LazyGraph.make ~eq:(==) force let word_size = Sys.word_size / 8 @@ -24,13 +24,13 @@ let size x = let compute_size x = let o = Obj.repr x in let vertices = LazyGraph.bfs graph o in - Enum.fold (fun sum (o',_,_) -> size o' + sum) 0 vertices + Gen.fold (fun sum (o',_,_) -> size o' + sum) 0 vertices let print_val fmt x = let o = Obj.repr x in let graph' = LazyGraph.map ~edges:(fun i -> [`Label (string_of_int i)]) ~vertices:(fun v -> [`Label (string_of_int v); `Shape "box"]) graph in - LazyGraph.Dot.pp ~name:"value" graph' fmt (Enum.singleton o) + LazyGraph.Dot.pp ~name:"value" graph' fmt (Gen.singleton o) let print_val_file filename x = let out = open_out filename in @@ -46,7 +46,7 @@ let process_val ~name x = module ISet = Set.Make(struct type t = int let compare = compare end) let mk_circ n = - let start = Enum.to_list (1--n) in + let start = Gen.to_list (1--n) in (* make the end of the list point to its beginning *) let rec cycle l = match l with | [] -> assert false @@ -57,10 +57,10 @@ let mk_circ n = start let _ = - let s = Enum.fold (fun s x -> ISet.add x s) ISet.empty (1--100) in + let s = Gen.fold (fun s x -> ISet.add x s) ISet.empty (1--100) in process_val ~name:"foo" s; - let l = Enum.to_list (Enum.map (fun i -> Enum.to_list (i--(i+42))) - (Enum.of_list [0;100;1000])) in + let l = Gen.to_list (Gen.map (fun i -> Gen.to_list (i--(i+42))) + (Gen.of_list [0;100;1000])) in process_val ~name:"bar" l; let l' = mk_circ 100 in process_val ~name:"baaz" l'; diff --git a/gen.ml b/gen.ml index 03058919..f567b9cf 100644 --- a/gen.ml +++ b/gen.ml @@ -798,14 +798,6 @@ let pp ?(start="") ?(stop="") ?(sep=",") ?(horizontal=false) pp_elem formatter e next true; Format.fprintf formatter "%s@]" stop -let (@@) = append - -let (>>=) e f = flatMap f e - -let (--) = int_range - -let (|>) x f = f x - module Infix = struct let (@@) = append @@ -815,3 +807,5 @@ module Infix = struct let (|>) x f = f x end + +include Infix diff --git a/gen.mli b/gen.mli index e87be95e..fa55d18f 100644 --- a/gen.mli +++ b/gen.mli @@ -278,15 +278,6 @@ val pp : ?start:string -> ?stop:string -> ?sep:string -> ?horizontal:bool -> (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit (** Pretty print an enum *) - -val (@@) : 'a t -> 'a t -> 'a t - -val (>>=) : 'a t -> ('a -> 'b t) -> 'b t - -val (--) : int -> int -> int t - -val (|>) : 'a -> ('a -> 'b) -> 'b - module Infix : sig val (@@) : 'a t -> 'a t -> 'a t @@ -297,3 +288,10 @@ module Infix : sig val (|>) : 'a -> ('a -> 'b) -> 'b end +val (@@) : 'a t -> 'a t -> 'a t + +val (>>=) : 'a t -> ('a -> 'b t) -> 'b t + +val (--) : int -> int -> int t + +val (|>) : 'a -> ('a -> 'b) -> 'b