Skip to content

Commit 2ecc0e6

Browse files
authored
Update do notation section re rebindable syntax (#265)
* Update do notation section re rebindable syntax * Update Syntax.md * Update Syntax.md
1 parent 3000ce1 commit 2ecc0e6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

language/Syntax.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,22 +566,21 @@ maybeSum a b = do
566566
```
567567

568568
`maybeSum` takes two values of type ``Maybe Number`` and returns their sum if neither value is `Nothing`.
569-
570-
When using `do` notation, there must be a corresponding instance of the `Monad` type class for the return type.
571-
569+
572570
Statements can have the following form:
573571

574-
- `a <- x` which desugars to `x >>= \a -> ...`
575-
- `x` which desugars to `x >>= \_ -> ...` or just `x` if this is the last statement.
572+
- `a <- x` which desugars to `bind x \a -> ...`
573+
- `x` which desugars to `bind x \_ -> ...` or just `x` if this is the last statement.
576574
- A let binding `let a = x`. Note the lack of the `in` keyword.
577575

578576
The example `maybeSum` desugars to::
579577

580578
``` purescript
581579
maybeSum a b =
582-
a >>= \n ->
583-
b >>= \m ->
580+
bind a \n ->
581+
bind b \m ->
584582
let result = n + m
585583
in pure result
586584
```
587-
Note: (>>=) is the `bind` function for the `Bind` type as defined in the [Prelude package](https://pursuit.purescript.org/packages/purescript-prelude/4.1.0/docs/Prelude#t:Bind).
585+
586+
In practice, you will usually be using [`bind` from the Prelude](https://pursuit.purescript.org/packages/purescript-prelude/docs/Control.Bind#v:bind), but the desugaring will use whichever `bind` is in scope. When using `bind` from the Prelude, there must be an instance of the `Monad` type class for the return type.

0 commit comments

Comments
 (0)