-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringcard.sml
67 lines (53 loc) · 1.35 KB
/
stringcard.sml
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
(*functor translateStringCar(card2 : string) : CARD = struct
*)
structure StringCard : CARD = struct
type 'a card = string
type slot = int
type slot' = int
type field = unit
fun untyped c = c
fun cast c = c
(* combinators *)
val I = "I"
val S = "S"
val K = "K"
val put = "put"
(* numbers *)
val zero = "zero"
val succ = "succ"
val dbl = "dbl"
(* slots *)
val get = "get"
val copy = "copy"
(* vitality *)
type u = unit
val inc = "inc"
val dec = "dec"
val attack = "attack"
val help = "help"
val revive = "revive"
val zombie = "zombie"
end
functor TranslateStringFn(Card2 : CARD) : CARD_TRANSLATE = struct
structure C1 = StringCard
structure C2 = Card2
exception Failed of string
fun translate t =
case t
of "I" => C2.cast C2.I
| "S" => C2.cast C2.S
| "K" => C2.cast C2.K
| "put" => C2.cast C2.put
| "zero" => C2.cast C2.zero
| "succ" => C2.cast C2.succ
| "dbl" => C2.cast C2.dbl
| "get" => C2.cast C2.get
| "copy" => C2.cast C2.copy
| "inc" => C2.cast C2.inc
| "dec" => C2.cast C2.dec
| "attack" => C2.cast C2.attack
| "help" => C2.cast C2.help
| "revive" => C2.cast C2.revive
| "zombie" => C2.cast C2.zombie
| s => raise Failed ("'" ^ s ^ "' does not name any card")
end