Imported Upstream version 0.2
[pkg-ocaml-deriving-ocsigen.git] / lib / deriving_Eq.ml
blob30022f4786c0e8b1b2a896bceff40ea15fa6940c
1 (* Copyright Jeremy Yallop 2007.
2 This file is free software, distributed under the MIT license.
3 See the file COPYING for details.
4 *)
6 module type Eq =
7 sig
8 type a
9 val eq : a -> a -> bool
10 end
12 module Defaults (E : Eq) = E
14 module Eq_immutable(S : sig type a end) :
15 Eq with type a = S.a =
16 struct
17 type a = S.a
18 let eq = (=)
19 end
21 module Eq_mutable(S : sig type a end) :
22 Eq with type a = S.a =
23 struct
24 type a = S.a
25 let eq = (==)
26 end
28 module Eq_int = Eq_immutable(struct type a = int end)
29 module Eq_bool = Eq_immutable(struct type a = bool end)
30 module Eq_float = Eq_immutable(struct type a = float end)
31 module Eq_unit = Eq_immutable(struct type a = unit end)
32 module Eq_char = Eq_immutable(struct type a = char end)
33 module Eq_int32 = Eq_immutable(struct type a = int32 end)
34 module Eq_int64 = Eq_immutable(struct type a = int64 end)
35 module Eq_nativeint = Eq_immutable(struct type a = nativeint end)
37 module Eq_string = Eq_mutable(struct type a = string end)
38 module Eq_ref (E : Eq) = Eq_mutable(struct type a = E.a ref end)
39 module Eq_array (E : Eq) = Eq_mutable(struct type a = E.a array end)
41 module Eq_option (E : Eq)
42 : Eq with type a = E.a option =
43 struct
44 type a = E.a option
45 let eq l r = match l, r with
46 | None, None -> true
47 | Some l, Some r -> E.eq l r
48 | _ -> false
49 end
51 module Eq_map_s_t (E : Eq) (M : Map.S)
52 : Eq with type a = E.a M.t =
53 struct
54 type a = E.a M.t
55 let eq = M.equal (E.eq)
56 end
58 module Eq_list (E : Eq) :
59 Eq with type a = E.a list =
60 struct
61 type a = E.a list
62 let rec eq l r = match l, r with
63 | [], [] -> true
64 | (lfst::lrst), (rfst::rrst) when E.eq lfst rfst -> eq lrst rrst
65 | _ -> false
66 end
68 module Eq_num
69 : Eq with type a = Num.num =
70 struct
71 type a = Num.num
72 let eq = Num.eq_num
73 end