-
Notifications
You must be signed in to change notification settings - Fork 0
/
Overview.fold
189 lines (125 loc) · 2.35 KB
/
Overview.fold
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env fold
-- ## Comments
-- This is a comment
-- TODO: Add some features.
-- XXX: Important notice.
-- FIXME: Don't forget about this issue!
-- WHAT THE HACK?
{{ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. }}
-- ## Polymorphic Variants
`Continue `foo
`Color 0xFF00FF
`Point (20.0, 0.0)
-- ## Characters
'x' 'a'
'\t' '\n'
'\99' '\9' -- Invalid char syntax
-- ## Booleans
True False
-- ## Numbers
0 1 42 100 322
0.0 3.14 0.999
0x998 0b1001
-- ## Strings
"Hello, World!"
"Hello, $name!"
"""
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
"""
"""
<div id="content">
$(Post.content)
</div>
"""
-- ## Structures
mod Person
...
end
sig Ord
...
end
ext List
...
end
-- ## Statements
assert True
ignore (2 + 2)
undefined
-- ## Module Operations
open Control.Monad
load Opium.App
include (Printable Person)
-- ## Conditionals
if True then `OK
else `Error 102
when
x < 0 -> -1
x > 0 -> +1
otherwise -> 0
end
unless (' ' in name)
print "Enter your full name!"
end
case color
`Red -> "red"
`Green -> "green"
`Blue -> "blue"
end
-- ## Loops
for i in [0..9]
print "i = $i"
end
flag = ref True
while flag!
if is_done ()
flag := False
end
end
-- ## Keywords
result = do
a = 32
b = 110
sqrt (-4 * a * b / 2)
end
let
a = 32
b = 110
in
sqrt (-4 * a * b / 2)
end
fun hello name
print "Hello, $name!"
end
-- ## Macro
macro if $test then $true_expr else $false_expr
```
case $test
True -> $true_expr
False -> $false_expr
end
```
end
-- ## Type
type Point =
{ x :: Float,
y :: Float }
Int Bool Char String
List a
List (Int, { x :: Float, y :: Float }) -> Map Char Float
-- ## Delimiters
( ) { } [ ]
-- ## Operators
:: -> <- ~> $ @ |> >>
-- ## Function Definition and Application
range from: (start = 0) to: stop by: (step = 1) =
if start == stop then []
else start & range from: (start + 1) to: stop by: step
range from: 10 to: 100 by: 2
hello name :: String -> () =
print "Hello, $name!"