Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | fun 'a printSize (name: string, value: 'a): unit= |
2 | (print "The size of " | |
3 | ; print name | |
4 | ; print " is = " | |
5 | ; print (Int.toString (MLton.size value)) | |
6 | ; print " bytes.\n") | |
7 | ||
8 | val l = [1, 2, 3, 4] | |
9 | ||
10 | val _ = | |
11 | ( | |
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, | |
31 | Word64.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), | |
35 | Word64.fromInt i))) | |
36 | ; printSize ("a (word64 * word64) array of length 10", | |
37 | Array.tabulate (10, fn i => (Word64.fromInt (i + 1), | |
38 | Word64.fromInt i))) | |
39 | ; printSize ("a (word16 * word64) array of length 10", | |
40 | Array.tabulate (10, fn i => (Word16.fromInt (i + 1), | |
41 | Word64.fromInt i))) | |
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", | |
45 | let val t = (0, 1) in | |
46 | Array.tabulate (10, fn _ => t) | |
47 | end) | |
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) | |
53 | end) | |
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) | |
65 | ) | |
66 | ||
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. | |
70 | *) | |
71 | val _ = if 10 = foldl (op +) 0 l | |
72 | then () | |
73 | else raise Fail "bug" |