[MLton-commit] r5987

Vesa Karvonen vesak at mlton.org
Sat Sep 1 11:04:53 PDT 2007


Hash once, lazily.
----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/generic/unstable/detail/hash-univ.sml

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

Modified: mltonlib/trunk/com/ssh/generic/unstable/detail/hash-univ.sml
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/detail/hash-univ.sml	2007-09-01 16:56:32 UTC (rev 5986)
+++ mltonlib/trunk/com/ssh/generic/unstable/detail/hash-univ.sml	2007-09-01 18:04:53 UTC (rev 5987)
@@ -12,17 +12,22 @@
 end
 
 structure HashUniv :> HASH_UNIV = struct
-   datatype t = T of {value : Univ.t,
-                      methods : {eq : Univ.t BinPr.t,
-                                 hash : Univ.t -> Word.t} Ref.t}
+   (* <-- SML/NJ workaround *)
+   open TopLevel
+   (* SML/NJ workaround --> *)
+
+   datatype t = T of {value : Univ.t, hash : Word.t Lazy.t,
+                      methods : {eq : Univ.t BinPr.t} Ref.t}
    fun new {eq, hash} = let
       val (to, from) = Univ.Iso.new ()
-      val methods = ref {eq = BinPr.map from eq, hash = hash o from}
+      val methods = ref {eq = BinPr.map from eq}
    in
-      (fn value => T {value = to value, methods = methods},
+      (fn value => T {value = to value,
+                      hash = delay (fn () => hash value),
+                      methods = methods},
        fn T r => from (#value r))
    end
    fun eq (T l, T r) = #methods l = #methods r
                        andalso #eq (! (#methods l)) (#value l, #value r)
-   fun hash (T r) = #hash (! (#methods r)) (#value r)
+   fun hash (T r) = force (#hash r)
 end




More information about the MLton-commit mailing list