Elm Exactly

Rule 75d-atexp-let

Atomic ExpressionsE⊢atexp⇒v\jdg{E}{\atexp}{v}
E⊢dec⇒VEE+VE⊢exp⇒vE⊢let dec in exp⇒v\frac{\begin{array}{c}\jdg{E}{\dec}{\VE}\premsep\jdg{E+\VE}{\expm}{v}\end{array}}{\begin{array}{c}\jdg{E}{\kw{let}\ \dec\ \kw{in}\ \expm}{v}\end{array}}
(75)
Read it in its chapter·Permanent address: /standard/rules/d-atexp-let

Comments

Every binding of dec\dec is evaluated, whether or not exp\expm 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 / CaseInLetTest
    Checks 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 / DeepNestStressTest
    Deeply nested lists, tuples, records and `let` expressions can be built and taken apart.
  • elm / LambdaLetBoundaryTest
    Checks functions that bind values in a `let` and then return a lambda for their remaining arguments.
  • elm / LetBasicTest
    Two 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 / LetMultiFuncTest
    Two 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 / LetMultipleTest
    Five Int bindings in one `let` combined by two later bindings: their sum (15) and their product (120).
  • elm / LetNestedTest
    A `let` expression used as the definition of a binding in an outer `let`: the inner binding 10 is multiplied by 3, giving 30.
  • elm / LetRecClosureTest
    A 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 / LetSeparatedStagingTest
    A function defined with fewer parameters than its annotated type returns, from different `case` branches, lambdas that take the remaining arguments in different groupings.
  • elm / LetValueBindingTest
    A `let` binding `x = e` binds `x` to the value of `e`, evaluated once.
  • elm / LocalRecCaptureBoolTest
    A let-bound recursive function reads a Bool defined earlier in the same `let`, and the loop takes the step size that Bool selects.
  • elm / MinimalLetTest
    A let expression with one definition.
  • elm / MultiLocalTailRecTest
    Two independent self-recursive functions defined in the same `let` block, each calling itself in tail position, both run correctly.
  • elm / StandardLetStrictTest
    A `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 / TailRecClosureAccTest
    A 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.