Elm Exactly

Rule 124dm-topdec-val

Top-level DeclarationsE⊢topdec⇒I\jdg{E}{\topdec}{I}
E⊢valbind∙⇒VEE+Rec VE⊢var1′ ()⇒v1  ⋯  E+Rec VE⊢varn′ ()⇒vnE⊢valbind⇒{var1↦v1,…,varn↦vn} in Interface\frac{\begin{array}{c}\jdg{E}{\dmthunk{\valbind}}{\VE}\\ \jdg{E+\Rec\VE}{\var'_1\ \kw{()}}{v_1}\ \ \cdots\ \ \jdg{E+\Rec\VE}{\var'_n\ \kw{()}}{v_n}\end{array}}{\begin{array}{c}\jdg{E}{\valbind} {\{\var_1\mapsto v_1,\ldots,\var_n\mapsto v_n\}\ \text{in}\ \Interface}\end{array}}
(124)
Read it in its chapter·Permanent address: /standard/rules/dm-topdec-val

Comments

Here valbind\valbind is var1 = exp1 and ⋯ and varn = expn\var_1\ \kw{=}\ \expm_1\ \kw{and}\ \cdots\ \kw{and}\ \var_n\ \kw{=}\ \expm_n, and valbind∙\dmthunk{\valbind} and var1′,…,varn′\var'_1,\ldots,\var'_n are as in Section 7.5; the first premise is a sentence of the Core (Value Bindings), and the choice of the new variables does not affect the result. Each vari\var_i is bound to a value obtained once, when its module is evaluated. A reference to vari\var_i within the group evaluates expi∙\dmthunk{\expm_i} again in the same environment, which gives viv_i again, there being no state, unless expi\expm_i relies on the unspecified result of an equality of functions (Section 6.5). A top-level value is thus evaluated once only up to that non-determinism: where expi\expm_i compares functions, a reference to vari\var_i within its group may give another of the values that the equality of functions allows, and so differ from viv_i. Thus with ones = { head = 1, tail = \_ -> ones }, the expression (ones.tail ()).head evaluates to 1. In x = let f _ = x in f () the occurrence of x is delayed, so the restrictions of Section 3.7 admit it, but evaluating var1′ ()\var'_1\ \kw{()} needs var1′ ()\var'_1\ \kw{()} again, without end: no sentence about the declaration can be inferred, and the module has no meaning.

TeX source
\defnrule[r:dm-topdec-val]
  {\jdg{E}{\dmthunk{\valbind}}{\VE}\\
   \jdg{E+\Rec\VE}{\var'_1\ \kw{()}}{v_1}\ \ \cdots\ \
   \jdg{E+\Rec\VE}{\var'_n\ \kw{()}}{v_n}}
  {\jdg{E}{\valbind}
     {\{\var_1\mapsto v_1,\ldots,\var_n\mapsto v_n\}\ \text{in}\ \Interface}}

Tests (15)

  • elm / CompilerIssue2119MutualRecursionUnannotatedTest
    An exposed, unannotated, mutually recursive function used from another module compiles and runs.
  • elm / CompilerIssue2207MutualRecursionSecondFunctionTest
    The second of two exposed, unannotated, mutually recursive functions can be used from another module.
  • elm / CovLambdaBoundaryCaseBoundaryInARecursiveValueTest
    A top-level function defined as a lambda whose `case` returns a different lambda per branch, one of which calls the function recursively.
  • elm / EscapeTopLevelTupleTest
    A tuple defined as a top-level constant is destructured in a `let` pattern into its two components.
  • elm / FunctionValueChoiceTest
    Top-level values defined by an `if` that picks between two lambdas can be both called directly and passed to a local `foldl`, and a function returning a tuple from an `if` can be destructured.
  • elm / LssGapNoDecls
    A program with no type declarations calls one annotated top-level function.
  • elm / MutualRecursionTest
    Two top-level functions that call each other, `isEven` and `isOdd`, decide parity by counting down to zero.
  • elm / MutualRecursionThreeWayTest
    Three top-level functions that call each other in a cycle (`funcA` calls `funcB`, `funcB` calls `funcC`, `funcC` calls `funcA`) recurse correctly.
  • elm / NonZeroArityRecursionTest
    A self-recursive top-level function, `countDown : Int -> Int`, calls itself in tail position from 100 down to 0 and returns 0; the program logs `countDown: 0`.
  • elm / PureMutualRecursiveValueTest
    Two top-level values that refer to each other through lambdas can be defined and used.
  • elm / PureRecursiveValueThunkTest
    A top-level value that refers to itself inside a lambda can be defined and used.
  • elm / RecursiveFactorialTest
    A self-recursive top-level `factorial` returns 1 for 0 and 120 and 3628800 for 5 and 10.
  • elm / RecursiveFibonacciTest
    A top-level `fib` that calls itself twice per step returns 0, 1 and 55 for 0, 1 and 10.
  • elm / RecursiveTopLevelLambdaTest
    A top-level value defined as a lambda that refers to itself can be called recursively.
  • elm / TailRecursiveSumTest
    A tail-recursive accumulator function sums the integers from 1 to n correctly for n = 5, 10 and 100.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:dm-topdec-val] 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.