[MLton-commit] r5561

Ville Laurikari ville at mlton.org
Fri May 18 02:35:11 PDT 2007


Indentation.

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

U   mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/detail/mt-19937.sml
U   mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/public/rng.sig
U   mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/test/first-5000.sml
U   mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/tests.mlb

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

Modified: mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/detail/mt-19937.sml
===================================================================
--- mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/detail/mt-19937.sml	2007-05-16 15:31:52 UTC (rev 5560)
+++ mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/detail/mt-19937.sml	2007-05-18 09:35:10 UTC (rev 5561)
@@ -1,69 +1,69 @@
-structure MersenneTwister: RNG = struct
-  open Word32
-  val && = andb
-  val || = orb
-  val op^ = xorb
-  infix >> << && ||
+structure MersenneTwister : RNG = struct
+   open Word32
+   val && = andb
+   val || = orb
+   val op^ = xorb
+   infix >> << && ||
 
-  val n = 0w624
-  val m = 0w397
+   val n = 0w624
+   val m = 0w397
 
-  datatype t = D of {mt: word array,
-                     i: word ref}
+   datatype t = D of {mt: word array, i: word ref}
 
-  fun new seed = let
-    val mt = Array.array(toIntX n, 0w0)
-    val _ = Array.update (mt, 0, seed);
-    fun loop (prev, i) =
-      if i < n then
-        let
-          val v = 0w1812433253 * (prev ^ (prev >> 0w30)) + i
-        in (
-          Array.update (mt, toIntX i, v);
-          loop (v, i + 0w1) )
-        end
-      else i
-    val i = loop (seed, 0w1)
-  in
-    D {mt = mt, i = ref i}
-  end
+   fun new seed = let
+      val mt = Array.array(toIntX n, 0w0)
+      val _ = Array.update (mt, 0, seed)
+      fun loop (prev, i) =
+          if i < n then
+             let
+                val v = 0w1812433253 * (prev ^ (prev >> 0w30)) + i
+             in
+                Array.update (mt, toIntX i, v)
+              ; loop (v, i + 0w1)
+             end
+          else i
+      val i = loop (seed, 0w1)
+   in
+      D {mt = mt, i = ref i}
+   end
 
-  fun twist (mt, i, a, b) = let
-    val y1 = Array.sub (mt, toIntX a) && 0wx80000000
-    val y2 = Array.sub (mt, toIntX b) && 0wx7fffffff
-    val y = y1 || y2
-    val v = (y >> 0w1) ^ (if (y && 0w1) = 0w0 then 0w0 else 0wx9908b0df)
-  in
-    Array.update (mt, toIntX a, Array.sub (mt, toIntX i) ^ v)
-  end
+   fun twist (mt, i, a, b) = let
+      val y1 = Array.sub (mt, toIntX a) && 0wx80000000
+      val y2 = Array.sub (mt, toIntX b) && 0wx7fffffff
+      val y = y1 || y2
+      val v = (y >> 0w1) ^ (if (y && 0w1) = 0w0 then 0w0 else 0wx9908b0df)
+   in
+      Array.update (mt, toIntX a, Array.sub (mt, toIntX i) ^ v)
+   end
 
-  fun generate mt = let
-    fun loop (k, max, add) =
-      if k < max then (
-        twist (mt, k + add, k, k + 0w1);
-        loop (k + 0w1, max, add) )
-      else ()
-  in ( loop (0w0, n - m, m);
-       loop (n - m, n - 0w1, m - n);
-       twist (mt, m - 0w1, n - 0w1, 0w0);
-       0w0 )
-  end
+   fun generate mt = let
+      fun loop (k, max, add) =
+          if k < max then
+             (twist (mt, k + add, k, k + 0w1)
+            ; loop (k + 0w1, max, add))
+          else ()
+   in
+      loop (0w0, n - m, m)
+    ; loop (n - m, n - 0w1, m - n)
+    ; twist (mt, m - 0w1, n - 0w1, 0w0)
+    ; 0w0
+   end
 
-  fun temper y = let
-    val y = y ^ (y >> 0w11)
-    val y = y ^ ((y << 0w7) && 0wx9d2c5680)
-    val y = y ^ ((y << 0w15) && 0wxefc60000)
-    val y = y ^ (y >> 0w18)
-  in y end
+   fun temper y = let
+      val y = y ^ (y >> 0w11)
+      val y = y ^ ((y << 0w7) && 0wx9d2c5680)
+      val y = y ^ ((y << 0w15) && 0wxefc60000)
+      val y = y ^ (y >> 0w18)
+   in y end
 
-  fun rand (D self) = let
-    val i = !(#i self)
-    val mt = #mt self
-    val i = if i >= n then generate mt else i
-    val y = temper (Array.sub (mt, toIntX i))
-  in (
-    (#i self) := i + 0w1;
-    y )
-  end
+   fun rand (D self) = let
+      val i = !(#i self)
+      val mt = #mt self
+      val i = if i >= n then generate mt else i
+      val y = temper (Array.sub (mt, toIntX i))
+   in
+      (#i self) := i + 0w1
+    ; y
+   end
 
 end

Modified: mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/public/rng.sig
===================================================================
--- mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/public/rng.sig	2007-05-16 15:31:52 UTC (rev 5560)
+++ mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/public/rng.sig	2007-05-18 09:35:10 UTC (rev 5561)
@@ -3,15 +3,15 @@
  * objects.
  *)
 signature RNG = sig
-  type t
+   type t
 
-  val new: word -> t
-  (**
-   * Creates a new random number generator and seeds it with the
-   * given seed.
-   *)
+   val new: word -> t
+   (**
+    * Creates a new random number generator and seeds it with the
+    * given seed.
+    *)
 
-  val rand: t -> word
-  (** Returns the next 32 bit random number. *)
+   val rand: t -> word
+   (** Returns the next 32 bit random number. *)
 
 end

Modified: mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/test/first-5000.sml
===================================================================
--- mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/test/first-5000.sml	2007-05-16 15:31:52 UTC (rev 5560)
+++ mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/test/first-5000.sml	2007-05-18 09:35:10 UTC (rev 5561)
@@ -1,13 +1,13 @@
 val () = let
-  open MersenneTwister
-  val mt = new 0w1234567890
-  fun loop 5000 = ()
-    | loop i = (
-      print (Word32.toString (rand mt));
-      if (i + 1) mod 8 = 0 then
-        print "\n"
-      else
-        print " ";
-      loop (i + 1) )
-  val _ = loop 0
+   open MersenneTwister
+   val mt = new 0w1234567890
+   fun loop 5000 = ()
+     | loop i =
+       (print (Word32.toString (rand mt))
+      ; if (i + 1) mod 8 = 0 then
+           print "\n"
+        else
+           print " ";
+        loop (i + 1))
+   val _ = loop 0
 in () end

Modified: mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/tests.mlb
===================================================================
--- mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/tests.mlb	2007-05-16 15:31:52 UTC (rev 5560)
+++ mltonlib/trunk/org/mlton/ville/mersenne-twister/unstable/tests.mlb	2007-05-18 09:35:10 UTC (rev 5561)
@@ -1,7 +1,7 @@
 local
-  $(SML_LIB)/basis/basis.mlb
+   $(SML_LIB)/basis/basis.mlb
 
-  lib.mlb
-  test/first-5000.sml
+   lib.mlb
+   test/first-5000.sml
 in
 end




More information about the MLton-commit mailing list