-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.vt
More file actions
125 lines (104 loc) · 2.89 KB
/
Copy pathtest.vt
File metadata and controls
125 lines (104 loc) · 2.89 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
(enum option (
None
(Some 'a)
))
; (val ('a) print_option ((('a) option)) -> void)
; (let print_option (x) (match x (
; (with None (print "none"))
; (with Some x' (print x')))))
; (val ('a) print_stuff ('a) -> 'a)
; (let print_stuff (x) (print x))
; (val print_i8 (i8) -> i8)
; (let print_i8 (x) (print x))
; (val print_string (string) -> string)
; (let print_string (x) (print x))
; (val ('a 'b) map (
; (('a) option)
; (('a) -> 'b)
; ) -> (('b) option))
; (let map (x fn) (match x (
; (with None { (print "nothing") (option::None) })
; (with Some x' (option::Some (fn x')))
; )))
; (exception Foo i8)
; (exception Bar)
; Stolen from http://dev.realworldocaml.org/records.html
(type service_info {
(val service_name string) ; eg, ssh
(val port i16) ; eg, 22
(val protocol string) ; eg, tcp
})
; (val fazoom (service_info) -> void)
; (let fazoom (sv) {
; (let s (.. sv.service_name " " sv.port "/" sv.protocol))
; (print s)
; })
(type heh {
(val sv service_info)
})
(type wat {
(val x i64)
})
(val main () -> i64)
(let main () {
; (let n (option::None))
; (let sa (option::Some 42))
; (let si (option::Some 42))
; (let ss (option::Some "Hello, World!"))
; ; (print_option n)
; (map n print_stuff)
; (map sa print_stuff)
; (map si print_i8)
; (map ss print_string)
; (try (throw Foo "Hello, World!") (
; (catch Bar (print 0))
; (catch Foo x (print_i8 x))
; ))
; (let sv_info (service_info {
; (.service_name "ssh")
; (.port 22)
; (.protocol "tcp")
; }))
; (print sv_info)
; (print_string sv_info.protocol)
; (print sv_info)
; (fazoom sv_info)
; (print (+ 0 1 2 3 4 5))
; (print (- 0 1 2 3 4 5))
; (print ( * 1 2 3 4 5))
; (print (/ 80 10 4 2))
; (if (< 0 1) (print "yep") (print "nope"))
; (if (> 0 1) (print "yep") (print "nope"))
; (if (= 0 1) (print "yep") (print "nope"))
; (if (!= 0 1) (print "yep") (print "nope"))
; (print (.. "< 0 1 := " (if (< 0 1) "yep" "nope")))
; (print (.. "> 0 1 := " (if (> 0 1) "yep" "nope")))
; (print (.. "= 0 1 := " (if (= 0 1) "yep" "nope")))
; (print (.. "!= 0 1 := " (if (!= 0 1) "yep" "nope")))
(let h (heh {
(.sv (service_info {
(.service_name "nice")
(.port 69)
(.protocol "tcp")
}))
}))
(let sv (& h.sv))
(print (& sv))
(print sv)
(print (.. "pointer: " (& sv)))
(print (.. "value: " sv))
; (print (& h.sv))
; (print sv)
; (print sv.service_name)
; (print h.sv.service_name)
; (print h.sv.port)
; (print h.sv.protocol)
; (let i 42) ; i is an i64
; (let i' (& i)) ; i' is a pointer to i64
; (let x (&* i')); x is an i64
; (let w (wat {
; (.x 0)
; }))
; (print w.x)
0
})