Merge branch 'master' of https://codeberg.org/catseye/Lanthorn
Chris Pressey
1 year, 8 months ago
0 | 0 |
Lanthorn
|
1 | 1 |
========
|
2 | 2 |
|
3 | |
_Version 1.0_
|
|
3 |
Version 1.0 | _Entry_ @ [catseye.tc](https://catseye.tc/node/Lanthorn)
|
|
4 |
| _See also:_ [Lariat](https://catseye.tc/node/Lariat)
|
|
5 |
* [Iphigeneia](https://catseye.tc/node/Iphigeneia)
|
4 | 6 |
|
5 | 7 |
When I first came across a explanation of how `letrec` works, it was
|
6 | 8 |
in terms of updating references: each of the names is bound to a cell,
|
|
40 | 42 |
...and turn it into this.
|
41 | 43 |
|
42 | 44 |
let
|
43 | |
odd0 = fun(x, odd$1, even$1) ->
|
|
45 |
odd0 = fun(x, odd1, even1) ->
|
44 | 46 |
let
|
45 | 47 |
odd = fun(x) -> odd1(x, odd1, even1)
|
46 | 48 |
even = fun(x) -> even1(x, odd1, even1)
|
0 | 0 |
module Language.Lanthorn.LetRec where
|
1 | 1 |
|
2 | 2 |
import Language.Lanthorn.AST
|
3 | |
import Language.Lanthorn.Pretty
|
4 | 3 |
|
5 | 4 |
|
6 | 5 |
convert (Fun formals body) = Fun formals (convert body)
|
|
13 | 12 |
convertBindings :: [(String, Expr)] -> [(String, Expr)]
|
14 | 13 |
convertBindings [] = []
|
15 | 14 |
convertBindings ((name, expr):rest) = ((name, (convert expr)):(convertBindings rest))
|
16 | |
|
17 | |
convertArms [] = []
|
18 | |
convertArms ((ante, cons):rest) = (((convert ante), (convert cons)):(convertArms rest))
|
19 | 15 |
|
20 | 16 |
convertToLetStar :: [(String, Expr)] -> Expr -> Expr
|
21 | 17 |
convertToLetStar bindings body =
|