Rule 124dm-topdec-val
Comments
Here is , and and 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 is bound to a value obtained once, when its module is evaluated. A reference to within the group evaluates again in the same environment, which gives again, there being no state, unless 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 compares functions, a reference to within its group may give another of the values that the equality of functions allows, and so differ from . 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 needs 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 / CompilerIssue2119MutualRecursionUnannotatedTestAn exposed, unannotated, mutually recursive function used from another module compiles and runs.
- elm / CompilerIssue2207MutualRecursionSecondFunctionTestThe second of two exposed, unannotated, mutually recursive functions can be used from another module.
- elm / CovLambdaBoundaryCaseBoundaryInARecursiveValueTestA top-level function defined as a lambda whose `case` returns a different lambda per branch, one of which calls the function recursively.
- elm / EscapeTopLevelTupleTestA tuple defined as a top-level constant is destructured in a `let` pattern into its two components.
- elm / FunctionValueChoiceTestTop-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 / LssGapNoDeclsA program with no type declarations calls one annotated top-level function.
- elm / MutualRecursionTestTwo top-level functions that call each other, `isEven` and `isOdd`, decide parity by counting down to zero.
- elm / MutualRecursionThreeWayTestThree top-level functions that call each other in a cycle (`funcA` calls `funcB`, `funcB` calls `funcC`, `funcC` calls `funcA`) recurse correctly.
- elm / NonZeroArityRecursionTestA 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 / PureMutualRecursiveValueTestTwo top-level values that refer to each other through lambdas can be defined and used.
- elm / PureRecursiveValueThunkTestA top-level value that refers to itself inside a lambda can be defined and used.
- elm / RecursiveFactorialTestA self-recursive top-level `factorial` returns 1 for 0 and 120 and 3628800 for 5 and 10.
- elm / RecursiveFibonacciTestA top-level `fib` that calls itself twice per step returns 0, 1 and 55 for 0, 1 and 10.
- elm / RecursiveTopLevelLambdaTestA top-level value defined as a lambda that refers to itself can be called recursively.
- elm / TailRecursiveSumTestA 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.