Commits

Dmitry Grebeniuk  committed 299e64e

changes around monoids

  • Participants
  • Parent commits a622105

Comments (0)

Files changed (2)

File src/cd_Int.ml

 module Int
  =
   struct
+
     type t = int;
+
     value compare = Pervasives.compare;
+
+    value monoid_plus = new Monoid.t 0 ( + );
+    value monoid_mult = new Monoid.t 1 ( * );
+    value monoid_land = new Monoid.t (-1) (* all 1 bits *) ( land );
+    value monoid_lor  = new Monoid.t 0 ( lor );
+
   end
 ;
-
-
-value monoid_plus : Monoid.t int =
-  object
-    method zero = 0;
-    method plus = ( + );
-  end
-;
-
-value monoid_mult : Monoid.t int =
-  object
-    method zero = 1;
-    method plus = ( * );
-  end
-;
-
-value monoid_mult : Monoid.t int =
-  object
-    method zero = 1;
-    method plus = ( * );
-  end
-;
-
-value monoid_land : Monoid.t int =
-  object
-    method zero = -1;  (* all 1 bits *)
-    method plus = ( land );
-  end
-;
-
-value monoid_lor : Monoid.t int =
-  object
-    method zero = 0;
-    method plus = ( lor );
-  end
-;

File src/monoid.ml

-class type t ['a] =
+class t ['a] z p =
   object
-    method zero : 'a;
-    method plus : 'a -> 'a -> 'a;
+    method zero : 'a = z;
+    method plus : 'a -> 'a -> 'a = p;
   end
 ;
-
-value map : ('a -> 'b) -> t 'a -> t 'b
-= fun f m ->
-    let fz = f m#zero
-    and p = m#plus in
-    object
-      method zero = fz;
-      method plus x y = p (f x) (f y);
-    end
-;