1 fun 'a
printSize (name
: string, value
: 'a
): unit
=
5 ; print (Int.toString (MLton
.size value
))
12 printSize ("a char", #
"c")
13 ; printSize ("an int list of length 4", l
)
14 ; printSize ("a string of length 10", "0123456789")
15 ; printSize ("an int array of length 10", Array
.tabulate (10, fn _
=> 0))
16 ; printSize ("a double array of length 10",
17 Array
.tabulate (10, fn _
=> 0.0))
18 ; printSize ("a (word32 * double) array of length 10",
19 Array
.tabulate (10, fn i
=> (Word32
.fromInt i
, 0.0)))
20 ; printSize ("a (word32 * word32 * double) array of length 10",
21 Array
.tabulate (10, fn i
=> (Word32
.fromInt (i
+ 1),
22 Word32
.fromInt i
, 0.0)))
23 ; printSize ("a (word64 * double) array of length 10",
24 Array
.tabulate (10, fn i
=> (Word64
.fromInt (i
+ 1), 0.0)))
25 ; printSize ("a (word16 * double) array of length 10",
26 Array
.tabulate (10, fn i
=> (Word16
.fromInt (i
+ 1), 0.0)))
27 ; printSize ("a word64 array of length 10",
28 Array
.tabulate (10, fn i
=> Word64
.fromInt i
))
29 ; printSize ("a (word32 * word64) array of length 10",
30 Array
.tabulate (10, fn i
=> (Word32
.fromInt i
,
32 ; printSize ("a (word32 * word32 * word64) array of length 10",
33 Array
.tabulate (10, fn i
=> (Word32
.fromInt i
,
34 Word32
.fromInt (i
+ 1),
36 ; printSize ("a (word64 * word64) array of length 10",
37 Array
.tabulate (10, fn i
=> (Word64
.fromInt (i
+ 1),
39 ; printSize ("a (word16 * word64) array of length 10",
40 Array
.tabulate (10, fn i
=> (Word16
.fromInt (i
+ 1),
42 ; printSize ("an array of length 10 of 2-ples of ints",
43 Array
.tabulate (10, fn i
=> (i
, i
+ 1)))
44 ; printSize ("an array of length 10 of 2-ples of (shared) ints",
46 Array
.tabulate (10, fn _
=> t
)
48 ; printSize ("an array of length 10 of arrays of length 20 of ints",
49 Array
.tabulate (10, fn i
=> Array
.tabulate (20, fn j
=> i
+ j
)))
50 ; printSize ("an array of length 10 of (shared) arrays of length 20 of ints",
51 let val a
= Array
.tabulate (20, fn j
=> j
)
52 in Array
.tabulate (10, fn i
=> a
)
54 ; printSize ("an array of length 10 of tuples of word16 * (arrays of length 20 of ints)",
55 Array
.tabulate (10, fn i
=> (Word16
.fromInt i
, Array
.tabulate (20, fn j
=> i
+ j
))))
56 ; printSize ("an array of length 10 of tuples of word32 * (arrays of length 20 of ints)",
57 Array
.tabulate (10, fn i
=> (Word32
.fromInt i
, Array
.tabulate (20, fn j
=> i
+ j
))))
58 ; printSize ("an array of length 10 of tuples of word64 * (arrays of length 20 of ints)",
59 Array
.tabulate (10, fn i
=> (Word64
.fromInt i
, Array
.tabulate (20, fn j
=> i
+ j
))))
60 ; printSize ("an array of length 10 of tuples of real32 * (arrays of length 20 of ints)",
61 Array
.tabulate (10, fn i
=> (Real32
.fromInt i
, Array
.tabulate (20, fn j
=> i
+ j
))))
62 ; printSize ("an array of length 10 of tuples of real64 * (arrays of length 20 of ints)",
63 Array
.tabulate (10, fn i
=> (Real64
.fromInt i
, Array
.tabulate (20, fn j
=> i
+ j
))))
64 ; printSize ("a useless function", fn _
=> 13)
67 (* This is here so that the list is
"useful".
68 * If it were removed
, then the
optimizer (remove
-unused
-constructors
)
69 * would remove l entirely
.
71 val _
= if 10 = foldl (op +) 0 l