forked from orion/obsidian
34 lines
485 B
Markdown
34 lines
485 B
Markdown
`let .. in ..` is an expression with some scoped variables, separated by newlines:
|
|
|
|
```haskell
|
|
let
|
|
a = 1
|
|
b = 2
|
|
in
|
|
a + b
|
|
```
|
|
|
|
> [!tip]
|
|
> there is a second local let-binding syntax, `where`:
|
|
> ```haskell
|
|
> a + b
|
|
> where
|
|
> a = 1
|
|
> b = 2
|
|
> ```
|
|
|
|
### Examples
|
|
|
|
Recursive Fibonacci generator, using a helper function `go`
|
|
```haskell
|
|
fib n =
|
|
let
|
|
go ns a b =
|
|
if Array.length ns == n then
|
|
ns
|
|
else
|
|
go (ns <> [a]) b (a + b)
|
|
in
|
|
go [] 1 1
|
|
```
|