[MLton-commit] r5662

Vesa Karvonen vesak at mlton.org
Thu Jun 21 09:32:38 PDT 2007


Cleaned up.  Optimized vector.  Documentation.
----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/generic/unstable/detail/value/eq.sml
U   mltonlib/trunk/com/ssh/generic/unstable/public/value/eq.sig

----------------------------------------------------------------------

Modified: mltonlib/trunk/com/ssh/generic/unstable/detail/value/eq.sml
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/detail/value/eq.sml	2007-06-20 23:04:22 UTC (rev 5661)
+++ mltonlib/trunk/com/ssh/generic/unstable/detail/value/eq.sml	2007-06-21 16:32:38 UTC (rev 5662)
@@ -7,8 +7,6 @@
 functor WithEq (Arg : OPEN_GENERIC) : EQ_GENERIC = struct
    (* <-- SML/NJ workaround *)
    open TopLevel
-   infix  7 *`
-   infix  6 +`
    infix  0 &
    (* SML/NJ workaround --> *)
 
@@ -25,62 +23,67 @@
      (structure Outer = Arg and Result = Eq and Rep = Eq.Closed
 
       fun iso b (a2b, _) = b o Pair.map (Sq.mk a2b)
+      val isoProduct = iso
+      val isoSum     = iso
 
-      val op *` = Product.equal
+      val op *`  = Product.equal
+      val T      = id
+      fun R _    = id
+      val tuple  = id
+      val record = id
+
       val op +` = Sum.equal
+      val unit  = op =
+      fun C0 _  = unit
+      fun C1 _  = id
+      val data  = id
 
       val Y = Tie.function
 
       fun op --> _ = failing "Eq.--> unsupported"
 
       val exn : Exn.t Rep.t Ref.t = ref GenericsUtil.failExnSq
-      fun regExn t (_, prj) =
+      fun regExn t (_, e2to) =
           Ref.modify (fn exn =>
                          fn (l, r) =>
-                            case prj l & prj r of
-                               SOME l & SOME r => t (l, r)
+                            case e2to l & e2to r of
+                               NONE   & NONE   => exn (l, r)
+                             | NONE   & SOME _ => false
                              | SOME _ & NONE   => false
-                             | NONE   & SOME _ => false
-                             | NONE   & NONE   => exn (l, r)) exn
+                             | SOME l & SOME r => t (l, r)) exn
       val exn = fn ? => !exn ?
 
+      val list = ListPair.allEq
+
+      fun seq length sub eq (l, r) = let
+         val lL = length l
+         val lR = length r
+         fun lp i = i = lL
+                    orelse eq (sub (l, i), sub (r, i))
+                           andalso lp (i+1)
+      in
+         lL = lR andalso lp 0
+      end
+
+      fun vector ? = seq Vector.length Vector.sub ?
       fun array _ = op =
+
       fun refc _ = op =
 
-      val list = ListPair.allEq
+      val largeInt  = op =
+      val largeReal = LargeReal.==
+      val largeWord = op =
 
-      fun vector eq = iso (list eq) Vector.isoList (* XXX can be optimized *)
-
       val bool   = op =
       val char   = op =
       val int    = op =
       val real   = Real.==
       val string = op =
-      val unit   = op =
       val word   = op =
 
-      val largeInt  = op =
-      val largeReal = LargeReal.==
-      val largeWord = op =
-
       val word8  = op =
-   (* val word16 = op = (* Word16 not provided by SML/NJ *) *)
       val word32 = op =
-      val word64 = op =
+      val word64 = op =)
 
-      (* Trivialities *)
-
-      val isoProduct = iso
-      val isoSum = iso
-
-      val T = id
-      fun R _ = id
-      val tuple = id
-      val record = id
-
-      fun C0 _ = unit
-      fun C1 _ = id
-      val data = id)
-
    open Layered
 end

Modified: mltonlib/trunk/com/ssh/generic/unstable/public/value/eq.sig
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/public/value/eq.sig	2007-06-20 23:04:22 UTC (rev 5661)
+++ mltonlib/trunk/com/ssh/generic/unstable/public/value/eq.sig	2007-06-21 16:32:38 UTC (rev 5662)
@@ -5,10 +5,22 @@
  *)
 
 (**
- * Signature for a generic equality relation.  For equality types the
- * semantics is the same as SML's built-in equality.  User defined types,
- * exceptions, and reals are given a natural, structural, semantics of
- * equality.  Functions, obviously, can't be supported.
+ * Signature for a generic equality relation.
+ *
+ * For equality types the semantics is the same as SML's equality.  For
+ * mutable types (refs and arrays) this means that two objects are
+ * considered equal if they have the same identity.  User defined
+ * datatypes and exceptions are given a structural semantics of equality.
+ * Specifically, two datatypes or exceptions are considered equal if they
+ * have the same constructor and the arguments of the constructors are
+ * considered equal.
+ *
+ * Currently, the equality of reals is the same as the {LargeReal.==}
+ * function.  This differs disturbingly from the equality for other types.
+ * In particular, {~0.0} and {0.0} are considered equal even though they
+ * are different values and {nan} is not considered equal to any value,
+ * including itself.  This is problematic for a number of important
+ * non-numerical applications such as serialization.
  *)
 signature EQ = sig
    structure Eq : OPEN_GENERIC_REP




More information about the MLton-commit mailing list