Commit 9b41a85e authored by Andrei Paskevich's avatar Andrei Paskevich
Browse files

move some useful generic stuff from Explicit_polymorphism to Util

parent 812c0be7
......@@ -56,11 +56,6 @@ end
module Utils = struct
(** parenthesing operator *)
let ($) f x = f x
let const x _ = x
let map_keys m = Mty.fold (fun key _ acc -> key::acc) m []
let map_values m = Mty.fold (fun _ value acc -> value::acc) m []
......@@ -141,12 +136,6 @@ module Utils = struct
(Debug.print_mtv Pretty.print_ty) tv_to_ty; flush stderr;*)
tv_to_ty
module Mint = Map.Make(
struct
type t = int
let compare = Pervasives.compare
end)
(** [bind_nums_to_type_vars l] takes a lsymbol [l], and binds 1..n (where
n is the number of type vars in [l]) to type vars of [l] *)
let bind_nums_to_type_vars l =
......
......@@ -17,6 +17,12 @@
(* *)
(**************************************************************************)
(* useful combinators *)
let ($) f x = f x
let const f _ = f
(* useful option combinators *)
let of_option = function None -> assert false | Some x -> x
......@@ -88,7 +94,12 @@ let any_fn pr _ t = pr t && raise FoldSkip
let ttrue _ = true
let ffalse _ = false
(* Set and Map on strings *)
(* Set and Map on ints and strings *)
module Int = struct type t = int let compare = Pervasives.compare end
module Sint = Set.Make(Int)
module Mint = Map.Make(Int)
module Sstr = Set.Make(String)
module Mstr = Map.Make(String)
......
......@@ -19,6 +19,10 @@
(** Useful functions *)
val ($) : ('a -> 'b) -> 'a -> 'b
val const : 'a -> 'b -> 'a
(* useful option combinators *)
val of_option : 'a option -> 'a
......@@ -49,18 +53,16 @@ val list_fold_product :
('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a
(** [list_fold_product f acc l1 l2] apply the function [f] with the
accumulator [acc] on all the pair of elements of [l1] and [l2]
tail-reccursive
*)
tail-reccursive *)
val list_fold_product_l :
('a -> 'b list -> 'a) -> 'a -> 'b list list -> 'a
(** generalisation of {! list_fold_product}
not tail-reccursive
*)
not tail-reccursive *)
val list_compare : ('a -> 'a -> int) -> 'a list -> 'a list -> int
(* boolean fold accumulators *)
(* boolean fold accumulators *)
exception FoldSkip
......@@ -72,7 +74,10 @@ val ffalse : 'a -> bool
val ttrue : 'a -> bool
(** [ttrue] constant function [true] *)
(* Set and Map on strings *)
(* Set and Map on ints and strings *)
module Sint : Set.S with type elt = int
module Mint : Map.S with type key = int
module Sstr : Set.S with type elt = string
module Mstr : Map.S with type key = string
......@@ -88,7 +93,6 @@ sig
val compare : t -> t -> int
end
module OrderedHash (X : Tagged) : OrderedHash with type t = X.t
module OrderedHashList (X : Tagged) : OrderedHash with type t = X.t list
......@@ -103,3 +107,4 @@ end
(* memoization *)
val memo : ?size:int -> ('a -> 'b) -> 'a -> 'b
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment