Restrictioncore-let-recursion
In a let, a definition refers to a definition (possibly itself) if a variable that the second binds occurs in the first. Every definition that lies on a cycle of this relation is a function binding with ; in particular, no destructuring binding and no definition without parameters lies on a cycle, even when is a lambda expression. The corresponding restriction for top-level declarations is given in Chapter 3.
Tests (6)
- elm / CyclicValueALetValueDefinedByItselfTestA let-bound value defined in terms of itself is rejected with a CYCLIC VALUE error.
- elm / LetCycleThroughLambdaArgumentTestA `let` definition without parameters that lies on a cycle is rejected, even when the cycle goes through a lambda: here a lambda passed as an argument to `Result.andThen`.
- elm / LetCycleThroughRecordLambdaTestA `let` definition without parameters that lies on a cycle is rejected, even when the cycle goes through a lambda: here a record whose field is a lambda that refers back to the record.
- elm / LetMutualRecursionBetweenLocalsTestTwo functions defined in the same `let` call each other.
- elm / MutualLetRecClosuresTestTwo `let`-bound functions that call each other (`evenP` and `oddP`) are mutually recursive, and each returns a record holding a Bool result and a step count.
- elm / TailLoopMutualRecMutualRecursionInsideATailLoopTestA self tail-recursive function whose loop body defines a pair of mutually recursive local functions, and calls one of them to compute the next accumulator, gives the right result.
In Lean
This restriction is decided on the syntax tree, as the book states it, by Src.LetRecursion (StandardElmMech/Src/Restrictions.lean, line 245), whose decider the kernel runs; each written test program has a theorem that it meets the restrictions, or that it breaks this one. Broken by: CyclicValueALetValueDefinedByItselfTest, LetCycleThroughLambdaArgumentTest, LetCycleThroughRecordLambdaTest.
Discussions
Discuss this restriction·Search the discussions on GitHub
Discussions are on GitHub; one about this restriction has [res:core-let-recursion] 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.