Elm Exactly

Restrictioncore-let-recursion

Stated in Section 2.10 Syntactic Restrictions, under Value bindings.

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 var atpat1 ⋯ atpatn = exp\var\ \atpat_1\ \cdots\ \atpat_n\ \kw{=}\ \expm with n≥1n \geq 1; in particular, no destructuring binding and no definition var = exp\var\ \kw{=}\ \expm without parameters lies on a cycle, even when exp\expm is a lambda expression. The corresponding restriction for top-level declarations is given in Chapter 3.

Read it in its chapter·Permanent address: /standard/restrictions/core-let-recursion

Tests (6)

  • elm / CyclicValueALetValueDefinedByItselfTest
    A let-bound value defined in terms of itself is rejected with a CYCLIC VALUE error.
  • elm / LetCycleThroughLambdaArgumentTest
    A `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 / LetCycleThroughRecordLambdaTest
    A `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 / LetMutualRecursionBetweenLocalsTest
    Two functions defined in the same `let` call each other.
  • elm / MutualLetRecClosuresTest
    Two `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 / TailLoopMutualRecMutualRecursionInsideATailLoopTest
    A 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.