Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes for let and do in Syntax.md #69

Merged
merged 10 commits into from
Apr 24, 2017
14 changes: 7 additions & 7 deletions language/Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Numeric literals can be integers (type `Int`) or floating point numbers (type `N
``` purescript
16 :: Int
0xF0 :: Int
16.0 :: Float
16.0 :: Number
```

### Strings
Expand Down Expand Up @@ -402,7 +402,7 @@ conditional = if 2 > 1 then "ok" else "oops"

## Let and where bindings

The `let` keyword a collection of local declarations, which may be mutually recursive, and which may include type declarations:
The `let` keyword introduces a collection of local declarations, which may be mutually recursive, and which may include type declarations:

``` purescript
factorial :: Int -> Int
Expand All @@ -418,10 +418,10 @@ factorial =
The `where` keyword can also be used to introduce local declarations at the end of a value declaration:

``` purescript
factorial :: Number -> Number
factorial :: Int -> Int
factorial = go 1
where
go :: Number -> Number -> Number
go :: Int -> Int -> Int
go acc 1 = acc
go acc n = go (acc * n) (n - 1)
```
Expand Down Expand Up @@ -470,10 +470,10 @@ maybeSum a b = do
n <- a
m <- b
let result = n + m
return result
pure result
```

`maybeSum` takes two values of type ``Maybe Number`` and returns their sum if neither number is `Nothing`.
`maybeSum` takes two values of type ``Maybe Number`` and returns their sum if neither value is `Nothing`.

When using `do` notation, there must be a corresponding instance of the `Monad` type class for the return type.

Expand All @@ -490,6 +490,6 @@ maybeSum a b =
a >>= \n ->
b >>= \m ->
let result = n + m
in return result
in pure result
```
Note: (>>=) is the `bind` function for the `Bind` type as defined in the [Prelude package](https://pursuit.purescript.org/packages/purescript-prelude/2.1.0/docs/Prelude#t:Bind).