Rule 75d-atexp-let
Atomic Expressions
(75)
Comments
Every binding of is evaluated, whether or not uses it: let _ = Debug.todo "x" in 1 has no value. A let binds a single group of bindings (Appendix A), so the evaluation of the groups of a let as written is ordered by the nesting of the equivalent form, and within a group the order does not matter.
TeX source
\defnrule[r:d-atexp-let]
{\jdg{E}{\dec}{\VE}\premsep\jdg{E+\VE}{\expm}{v}}
{\jdg{E}{\kw{let}\ \dec\ \kw{in}\ \expm}{v}}Tests (15)
- elm / CaseInLetTestChecks that a `case` expression on an `Order` can be the body of a `let` binding, with each of `GT`, `EQ` and `LT` selecting its own string.
- elm / DeepNestStressTestDeeply nested lists, tuples, records and `let` expressions can be built and taken apart.
- elm / LambdaLetBoundaryTestChecks functions that bind values in a `let` and then return a lambda for their remaining arguments.
- elm / LetBasicTestTwo groups of `let` bindings, where later bindings use earlier ones: `x + y` on two Int literals gives 5, and `"hello" ++ " " ++ "world"` gives `"hello world"`.
- elm / LetMultiFuncTestTwo named functions defined in one `let` and called from later bindings: a local `identity` returns its argument (1) and a local `const` returns the first of two (2).
- elm / LetMultipleTestFive Int bindings in one `let` combined by two later bindings: their sum (15) and their product (120).
- elm / LetNestedTestA `let` expression used as the definition of a binding in an outer `let`: the inner binding 10 is multiplied by 3, giving 30.
- elm / LetRecClosureTestA recursive function defined in a `let` block captures a parameter of the enclosing function and is used by an earlier binding of the same `let`.
- elm / LetSeparatedStagingTestA function defined with fewer parameters than its annotated type returns, from different `case` branches, lambdas that take the remaining arguments in different groupings.
- elm / LetValueBindingTestA `let` binding `x = e` binds `x` to the value of `e`, evaluated once.
- elm / LocalRecCaptureBoolTestA let-bound recursive function reads a Bool defined earlier in the same `let`, and the loop takes the step size that Bool selects.
- elm / MinimalLetTestA let expression with one definition.
- elm / MultiLocalTailRecTestTwo independent self-recursive functions defined in the same `let` block, each calling itself in tail position, both run correctly.
- elm / StandardLetStrictTestA `let` evaluates its declarations before its body, even a declaration whose value is not used: `let _ = Debug.todo "x" in 1` has no value, so the program stops there.
- elm / TailRecClosureAccTestA tail-recursive accumulator loop defined as a local function in a `let` gives the right result: `go` adds `m` to `acc` while counting `m` down to 0, so `recursiveLet 5` is 5 + 4 + 3 + 2 + 1 = 15.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:d-atexp-let] in its title.
A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.