Skip to content

Commit

Permalink
Merge #908
Browse files Browse the repository at this point in the history
908: Removed duplicate words in The gluon book r=Marwes a=gemmaro



Co-authored-by: gemmaro <[email protected]>
  • Loading branch information
bors[bot] and gemmaro authored Mar 25, 2021
2 parents 07da726 + dada8d6 commit 27cec6c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions book/src/anatomy-of-a-gluon-program.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ io.println line

There are two new concepts in play here, [implicit arguments](./syntax-and-semantics.html#implicit-arguments) and [do expressions](./syntax-and-semantics.html#do-expressions).

`do expressions` are similar to `let expressions` in that they let us us bind the result of an expression to a name which we can use later. Where they differ is that, rather binding the result of evaluating the expression itself, they expect the right hand side to be a monadic action such as `IO` and the value bound is the result of evaluating the action, which in this case is the `String` that that were input.
`do expressions` are similar to `let expressions` in that they let us bind the result of an expression to a name which we can use later. Where they differ is that, rather binding the result of evaluating the expression itself, they expect the right hand side to be a monadic action such as `IO` and the value bound is the result of evaluating the action, which in this case is the `String` that were input.

(As was alluded to in the previous paragraph `IO` is a `Monad`, a rather complex concept which I won't go into here as it is enough for our purposes to only consider the "IO monad" as something that describes how `IO` actions are run in sequence.)

`do expressions` don't just magically work with `IO` actions which is where `implicit arguments` come in, it lets us use the compiler to to implicitly insert certain function arguments by looking at the inferred types. This can be thought as a way to get something similar to `traits` in Rust but with a bit extra flexibility by requiring a bit of explicitness to let the compiler know what it can use as an implicit argument. Which is why we needed to add the `{ ? }` record pattern match, the `?` lets the compiler know that it should choose from the fields of the record when looking for an implicit argument. In this case the compiler sees that we use `IO` in the `do expression` and implicitly inserts an implicit [`Monad IO`][] value found in `std.io`, letting the `do expression` know how to sequence these two actions.
`do expressions` don't just magically work with `IO` actions which is where `implicit arguments` come in, it lets us use the compiler to implicitly insert certain function arguments by looking at the inferred types. This can be thought as a way to get something similar to `traits` in Rust but with a bit extra flexibility by requiring a bit of explicitness to let the compiler know what it can use as an implicit argument. Which is why we needed to add the `{ ? }` record pattern match, the `?` lets the compiler know that it should choose from the fields of the record when looking for an implicit argument. In this case the compiler sees that we use `IO` in the `do expression` and implicitly inserts an implicit [`Monad IO`][] value found in `std.io`, letting the `do expression` know how to sequence these two actions.

[`Monad IO`]:https://gluon-lang.org/doc/nightly/std/io.html#value.monad

Expand All @@ -43,7 +43,7 @@ io.println (show target_number)

The program should now output a random number between 1 and 100 on every run! We aren't checking if that number matches the input from the user yet however so lets do that next.

To check that the input is actually a number and retrieve retrieve it as such we can use the [`std.int.parse`][] function. We also need to trim whitespace from the line we read as it contains a trailing newline.
To check that the input is actually a number and retrieve it as such we can use the [`std.int.parse`][] function. We also need to trim whitespace from the line we read as it contains a trailing newline.

```f#,rust
let io @ { ? } = import! std.io
Expand Down

0 comments on commit 27cec6c

Please sign in to comment.