File: size2.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 (73 lines) | stat: -rw-r--r-- 4,038 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
fun 'a printSize (name: string, value: 'a): unit=
   (print "The size of "
    ; print name
    ; print " is = "
    ; print (Int.toString (MLton.size value))
    ; print " bytes.\n")

val l = [1, 2, 3, 4]

val _ =
   (
    printSize ("a char", #"c")
    ; printSize ("an int list of length 4", l)
    ; printSize ("a string of length 10", "0123456789")
    ; printSize ("an int array of length 10", Array.tabulate (10, fn _ => 0))
    ; printSize ("a double array of length 10",
                 Array.tabulate (10, fn _ => 0.0))
    ; printSize ("a (word32 * double) array of length 10",
                 Array.tabulate (10, fn i => (Word32.fromInt i, 0.0)))
    ; printSize ("a (word32 * word32 * double) array of length 10",
                 Array.tabulate (10, fn i => (Word32.fromInt (i + 1),
                                              Word32.fromInt i, 0.0)))
    ; printSize ("a (word64 * double) array of length 10",
                 Array.tabulate (10, fn i => (Word64.fromInt (i + 1), 0.0)))
    ; printSize ("a (word16 * double) array of length 10",
                 Array.tabulate (10, fn i => (Word16.fromInt (i + 1), 0.0)))
    ; printSize ("a word64 array of length 10",
                 Array.tabulate (10, fn i => Word64.fromInt i))
    ; printSize ("a (word32 * word64) array of length 10",
                 Array.tabulate (10, fn i => (Word32.fromInt i, 
                                              Word64.fromInt i)))
    ; printSize ("a (word32 * word32 * word64) array of length 10",
                 Array.tabulate (10, fn i => (Word32.fromInt i, 
                                              Word32.fromInt (i + 1),
                                              Word64.fromInt i)))
    ; printSize ("a (word64 * word64) array of length 10",
                 Array.tabulate (10, fn i => (Word64.fromInt (i + 1),
                                              Word64.fromInt i)))
    ; printSize ("a (word16 * word64) array of length 10",
                 Array.tabulate (10, fn i => (Word16.fromInt (i + 1),
                                              Word64.fromInt i)))
    ; printSize ("an array of length 10 of 2-ples of ints",
                 Array.tabulate (10, fn i => (i, i + 1)))
    ; printSize ("an array of length 10 of 2-ples of (shared) ints",
                 let val t = (0, 1) in
                 Array.tabulate (10, fn _ => t)
                 end)
    ; printSize ("an array of length 10 of arrays of length 20 of ints",
                 Array.tabulate (10, fn i => Array.tabulate (20, fn j => i + j)))
    ; printSize ("an array of length 10 of (shared) arrays of length 20 of ints",
                 let val a = Array.tabulate (20, fn j => j)
                 in Array.tabulate (10, fn i => a)
                 end)
    ; printSize ("an array of length 10 of tuples of word16 * (arrays of length 20 of ints)",
                 Array.tabulate (10, fn i => (Word16.fromInt i, Array.tabulate (20, fn j => i + j))))
    ; printSize ("an array of length 10 of tuples of word32 * (arrays of length 20 of ints)",
                 Array.tabulate (10, fn i => (Word32.fromInt i, Array.tabulate (20, fn j => i + j))))
    ; printSize ("an array of length 10 of tuples of word64 * (arrays of length 20 of ints)",
                 Array.tabulate (10, fn i => (Word64.fromInt i, Array.tabulate (20, fn j => i + j))))
    ; printSize ("an array of length 10 of tuples of real32 * (arrays of length 20 of ints)",
                 Array.tabulate (10, fn i => (Real32.fromInt i, Array.tabulate (20, fn j => i + j))))
    ; printSize ("an array of length 10 of tuples of real64 * (arrays of length 20 of ints)",
                 Array.tabulate (10, fn i => (Real64.fromInt i, Array.tabulate (20, fn j => i + j))))
    ; printSize ("a useless function", fn _ => 13)
    )

(* This is here so that the list is "useful".
 * If it were removed, then the optimizer (remove-unused-constructors)
 * would remove l entirely.
 *)
val _ = if 10 = foldl (op +) 0 l
           then ()
        else raise Fail "bug"