Skip to content

Commit 0e84c39

Browse files
authored
Merge pull request documentationjs#16 from purescript/chexxor-indentation-in-binding-blocks
Add "Indentation in binding blocks"
2 parents d46224f + c51f93a commit 0e84c39

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

language/Values.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,38 @@ factorial = go 1
338338
go acc n = go (acc * n) (n - 1)
339339
```
340340

341+
## Indentation in binding blocks
342+
343+
Indentation of a binding's body is significant. If defining multiple bindings, as in a let-in block, each binding must have the same level of indentation. The body of the binding's definition, then, must be further indented. To illustrate:
344+
345+
``` purescript
346+
f =
347+
-- The `let-in` block starts at an indentation of 2 spaces, so
348+
-- the bindings in it must start at an indentation greater than 2.
349+
let
350+
-- Because `x` is indented 4 spaces, `y` must also be indented 4 spaces.
351+
-- Its body, then, must have indentation greater than 4 spaces.
352+
x :: Int -> Int
353+
x a =
354+
-- This body is indented 2 spaces.
355+
a
356+
y :: Int -> Int
357+
y c =
358+
-- This body is indented 4 spaces.
359+
c
360+
in do
361+
-- Because `m` is indented 4 spaces from the start of the `let`,
362+
-- `n` must also be indented 4 spaces.
363+
-- Its body, then, must be greater than 4 spaces.
364+
let m =
365+
-- This body is indented 2 spaces.
366+
x (y 1)
367+
n =
368+
-- This body is indented 4 spaces.
369+
x 1
370+
log "test"
371+
```
372+
341373
## Do notation
342374

343375
The `do` keyword introduces simple syntactic sugar for monadic expressions.

0 commit comments

Comments
 (0)