File: cases.sml

package info (click to toggle)
mlton 20100608-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 34,980 kB
  • ctags: 69,089
  • sloc: ansic: 18,421; lisp: 2,879; makefile: 1,570; sh: 1,325; pascal: 256; asm: 97
file content (36 lines) | stat: -rw-r--r-- 542 bytes parent folder | download | duplicates (9)
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
fun test (f, a, r) =
   if f a = r
      then ()
   else raise Fail "bug"

val rec f =
   fn 0 => 0
    | 1 => 1
    | 2 => 2
    | i => f (i - 1)

val _ = test (f, 100, 2)

val rec f: word -> int =
   fn 0w0 => 0
    | 0w1 => 1
    | 0w2 => 2
    | w => f (w - 0w1)

val _ = test (f, 0w100, 2)

val rec f: Word8.word -> int =
   fn 0w0 => 0
    | 0w1 => 1
    | 0w2 => 2
    | w => f (w - 0w1)

val _ = test (f, 0w100, 2)

val rec f: char -> int =
   fn #"a" => 0
    | #"b" => 1
    | #"c" => 2
    | _ => f #"c"

val _ = test (f, #"d", 2)