File: ref-flatten.3.sml

package info (click to toggle)
mlton 20130715-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 60,900 kB
  • ctags: 69,386
  • sloc: xml: 34,418; ansic: 17,399; lisp: 2,879; makefile: 1,605; sh: 1,254; pascal: 256; python: 143; asm: 97
file content (23 lines) | stat: -rw-r--r-- 747 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(*
 * This example tests for a bug that was in refFlatten at one point.  The idea
 * is to allocate a ref cell outside a loop, and then allocate a tuple containing
 * the ref cell at each iteration of the loop.  At one point, refFlatten
 * mistakenly flattened the ref cell, which meant that it wasn't shared across
 * all the tuples allocated in the loop, as it should have been.
 *)
fun loop i =
   if i = 0
      then ()
   else
      let
         val r = ref 13
         val l = List.tabulate (10, fn i => (r, ref i))
         val (r1, r2) = List.nth (l, 0)
         val () = r1 := !r2
         val (r1, _) = List.nth (l, 1)
         val () = print (concat [Int.toString (!r1), "\n"])
      in
         loop (i - 1)
      end

val () = loop 2