You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
886: feat: Compile block expressions as monadic sequences r=Marwes a=Marwes
Rather than removing block expressions entirely, this changes them
to behave as sequence (`seq`) expressions.
```f#
io.println "Hello"
io.println "World"
// Is now equivalent to
seq io.println "Hello"
io.println "World"
```
Co-authored-by: Markus Westerlind <[email protected]>
Copy file name to clipboardExpand all lines: book/src/syntax-and-semantics.md
+21-5Lines changed: 21 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ If, on the other hand, you are familiar with functional languages you will be ri
8
8
9
9
### Identifiers and Literals
10
10
11
-
The simplest syntactical elements in Gluon are identifiers and literals and none of them should be especially surprising if you are experienced in programming.
11
+
The simplest syntactical elements in Gluon are identifiers and literals and none of them should be especially surprising if you are experienced in programming.
12
12
13
13
Identifiers are a sequence of alphanumeric characters including underscore ("\_") which are required to start with either a letter or an underscore. Literals come in four different forms - integer, float, string and character literals.
14
14
@@ -37,7 +37,7 @@ r###" "## "###
37
37
38
38
### Comments
39
39
40
-
Comments should be immediately familiar if you are accustomed to C-like languages.
40
+
Comments should be immediately familiar if you are accustomed to C-like languages.
41
41
42
42
`//` starts a line comment which is ended by a newline
43
43
@@ -206,7 +206,9 @@ Here, we write out a pattern for each of the variant's constructors and the valu
206
206
```f#,rust
207
207
match { x = 1.0, pi = 3.14 } with
208
208
| { x = y, pi } -> y + pi
209
+
```
209
210
211
+
```f#,rust
210
212
// Patterns can be nested as well
211
213
match { x = Some (Some 123) } with
212
214
| { x = Some None } -> 0
@@ -270,6 +272,9 @@ While we have seen that functions can be defined in let expressions it is often
270
272
```f#,rust
271
273
// \(<identifier)* -> <expr>
272
274
\x y -> x + y - 10
275
+
```
276
+
277
+
```f#,rust
273
278
// Equivalent to
274
279
let f x y = x + y - 10 in f
275
280
```
@@ -329,9 +334,9 @@ do { y } = Some { y = "" }
329
334
Some y
330
335
```
331
336
332
-
### Seq expressions
337
+
### Sequence expressions
333
338
334
-
`seq` expressions work just like `do` expressions, only they do not have a binding.
339
+
Sequence expressions work just like `do` expressions, only they do not have a binding.
335
340
336
341
```f#,rust
337
342
let io @ { ? } = import! std.io
@@ -340,6 +345,17 @@ seq io.print " "
340
345
io.println "world!"
341
346
```
342
347
348
+
The `seq` keyword can also be omitted.
349
+
350
+
```f#,rust
351
+
let io @ { ? } = import! std.io
352
+
io.print "Hello"
353
+
io.print " "
354
+
io.println "world!"
355
+
```
356
+
357
+
(In the future one of these ways are likely to be deprecated with only one way remaining, the formatter will be able to update the code in any case).
358
+
343
359
### Indentation
344
360
345
361
If you have been following along this far, you may be think that the syntax so far is pretty limiting. In particular, you wouldn't be wrong in thinking that the `let` and `type` syntax are clunky due to their need to be closed by the `in` keyword. Luckily, Gluon offers a more convenient way of writing bindings by relying on indentation.
@@ -386,7 +402,7 @@ module.id module.pi
386
402
387
403
## Typesystem
388
404
389
-
In gluon, identifiers starting with an uppercase letter is a type whereas identifiers starting with a lowercase letter are type variables.
405
+
In gluon, identifiers starting with an uppercase letter is a type whereas identifiers starting with a lowercase letter are type variables.
0 commit comments