Rule 91d-dec-rec
Declarations
(91)
Referred to from
- The comment on rule
d-exp-lambda(Chapter 6) - The comment on rule
d-dec-nonrec(Chapter 6) - Section D.3 Values Written in Elm
TeX source
\defnrule[r:d-dec-rec]
{\jdg{E}{\valbind}{\VE}\premsep\Dom\VE\cap\dcoreFV(\valbind)\neq\emptyset}
{\jdg{E}{\valbind}{\Rec\VE}}Tests (23)
- elm / AccessorFunctionFieldTailCallTestRecord accessors for function-typed fields can be passed as arguments of self-recursive tail calls.
- elm / AccessorPlaceholderAccessorOfAFunctionFieldPassedInTailCallsTestRecord accessors for function-typed fields can be passed as arguments of tail calls, at top level and in an unannotated let-bound function.
- elm / AnnotatedLetRecFnResultTestA recursive let-bound function whose type annotation has a function as its result works.
- elm / CharCaptureEscapedTailDefTestA tail-recursive local function that refers to a `Char` argument of its enclosing function still works when it is returned inside a list and called later.
- elm / CompilerIssue1766LetMutualRecursionMismatchTestMutually recursive let functions give a type a false "mismatch" with itself.
- elm / LetMutualRecursionBetweenLocalsTestTwo functions defined in the same `let` call each other.
- elm / LetRecClosureTestA 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 / LetRecMultiArgTestA recursive two-argument function defined in a `let` block calls itself with both arguments changed; `f 1 1` logs `result: 2`.
- elm / LocalMultiNonTailRecTestA let-bound recursive function that is not tail recursive, with an unannotated polymorphic type, is used at both Int and Float in the same body.
- elm / LocalRecCaptureBoolTestA let-bound recursive function reads a Bool defined earlier in the same `let`, and the loop takes the step size that Bool selects.
- elm / LocalRecCaptureKindsTestA let-bound recursive function that uses an Int, a Float, a Char, a Bool and a String from its enclosing scope gives the same result whether it is called directly or passed to a local `map`.
- elm / LocalRecCaptureSplitParamTestA let-bound recursive function reads a tuple parameter of the tail-recursive function that encloses it.
- elm / LocalTailRecSimpleTestAn annotated let-bound tail-recursive function with an accumulator computes the sum 1 + 2 + ... + 10 = 55.
- elm / MinimalLetRecursionTestA let definition of a function that calls itself.
- elm / MultiLocalTailRecTestTwo independent self-recursive functions defined in the same `let` block, each calling itself in tail position, both run correctly.
- 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 / MutualLetRecManyCapturesTestTwo mutually recursive `let`-bound functions inside a top-level function, both using all four of the enclosing function's parameters, compute the right result.
- elm / MutualLetRecNestedTestTwo mutually recursive `let`-bound functions defined inside a lambda that is returned from a top-level function use that function's parameters after it has returned.
- elm / PolyLetTailRecTwoTypesTestA let-bound, polymorphic, tail-recursive local `foldl` used at two different types in the same expression gives the right result for each.
- 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.
- elm / TailRecClosureAccTestA 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.
- elm / TailRecDeciderSearchTestA local function defined in a `let` that calls itself both in a tail position and in a non-tail position, as the scrutinee of a `case`, gives the right result.
- elm / TailRecFoldlCaseTestA hand-written left fold, defined as a self tail-recursive local function in `main`'s `let` and matching on the list with `case`, sums `[ 1, 2, 3 ]` to 6.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:d-dec-rec] 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.