Rule 79d-exp-lambda
Expressions
(79)
Comments
The fourth component of the closure is empty because a lambda introduces no recursively defined values; rule (91) supplies it for a recursive declaration. The closure holds the environment of this evaluation, so closures made in successive calls of a function hold the values of their own calls. Two evaluations of one lambda give closures that no rule distinguishes from one another by identity.
TeX source
\defnrule[r:d-exp-lambda]
{}
{\jdg{E}{\kw{\textbackslash}\,\atpat\ \kw{->}\ \expm}{(\atpat,\expm,E,\emptymap)}}Tests (52)
- elm / AnonymousFunctionTestAnonymous functions work as the function argument of higher-order functions.
- elm / CapturedStagedFuncCallTestA function parameter captured by a local helper and applied to two arguments works when the function passed in takes one argument and returns a function.
- elm / CaseReturnFunctionTestChecks that the branches of a `case` can each return a two-argument lambda, and that the returned function is applied with the right arithmetic.
- elm / CaseReturningLambdaTestChecks a `case` on a custom type whose first branch holds a nested `case` on a `String`, where every branch of both returns a two-argument lambda.
- elm / CharAstralClosureCaptureTestAn astral `Char` (code point above 0xFFFF) referred to by a lambda, or supplied as the first argument of a partially applied function, keeps its code point when the function is called later.
- 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 / ClosureCapture01TestA lambda returned from a function captures a single-constructor custom-type argument and unwraps it with `case` when called.
- elm / ClosureCapture02TestA lambda returned from a function captures a `Maybe String` argument and matches on it with `case` when called.
- elm / ClosureCapture03TestA lambda returned from a function captures a value of a two-constructor custom type, both of whose constructors carry a payload, and matches on it with `case` when called.
- elm / ClosureCapture04TestA lambda returned from a function captures two `Maybe Int` arguments, each used only as the subject of a `case`, and adds the extracted values.
- elm / ClosureCapture05TestA lambda returned from a function captures a custom-type value holding two `Maybe String`s, and when called matches on it and then on each `Maybe` in turn.
- elm / ClosureCaptureBoolTestPartially applying a `Bool -> Int -> Int` function to a `Bool` gives a function that remembers that `Bool`.
- elm / ClosureCaptureRecordTestA lambda returned from a function can use a captured record's fields, or the elements of a captured tuple bound by a `case` pattern.
- elm / ClosureCaptureTupleTestA lambda returned from a function captures a tuple and destructures it with a `let` pattern when called.
- elm / ClosureDifferentClosuresPerIfBranchInsideACaseTestA function whose body is a `case` containing an `if` chain returns a different lambda from each branch, and the chosen lambda is applied to a further argument.
- elm / CompilerIssue1813TcoClosureCapturesMutatedArgTestA lambda created in a self tail call keeps the argument value of its own call.
- elm / CompilerIssue2017TcoContinuationShadowedTestA lambda passed in a self tail call must call the original continuation, not itself.
- elm / CompilerIssue2221TcoContinuationTestA tail-recursive function that builds a continuation on each call computes `g 5 identity` as 120.
- elm / CompilerIssue2268TcoClosureCaptureTestLambdas created inside a tail-recursive function each keep the argument value they were created with.
- elm / CovLambdaBoundaryCaseBoundaryUnderAFunctionAliasTestA function whose result type is a type alias for a function type, with a `case` that returns a different lambda per branch.
- elm / DictMapStagedCaptureTestA two-argument function passed as a parameter and applied to both of its arguments inside a lambda that a mapping function calls with two arguments receives both of them.
- elm / EmbeddedEmptyStringCaptureTestA local function that refers to an empty string defined in the enclosing `let` sees it as empty: it is equal to `""`, and the captured string it returns is `""`.
- elm / EmbeddedNilCaptureTestA local function that refers to an empty list defined in the enclosing `let` matches it against the `[]` pattern.
- elm / EmbeddedNothingCaptureTestA local function that refers to a `Nothing` defined in the enclosing `let` matches it against the `Nothing` pattern.
- elm / FunctionChainedPartialApplicationTestPartially applying a three-argument lambda twice, one argument at a time, gives a function, which `Debug.log` prints as `<function>`.
- elm / FunctionMultiArgTestUnannotated top-level functions of three, four and five arguments return the sum of their arguments.
- 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 / HOParamApplyTwoTestA let-bound higher-order function that applies its function parameter to two arguments works with a two-parameter lambda.
- elm / HeteroClosureIntFloatTestPartial applications of two different functions, one that has been given an `Int` and one that has been given a `Float`, can be chosen by an `if` and then called.
- elm / HigherOrderFunctionChosenByIfTestA higher-order function chosen by an `if` and then applied to a function argument gives the right result.
- elm / HigherOrderFunctionFactoryTestA let-bound function that returns a lambda capturing its argument produces a working function.
- elm / HigherOrderReturnLambdaBasedOnConditionTestA let-bound function that returns one of two lambdas depending on a `Bool` can be applied to a further argument in the same call.
- elm / HigherOrderTripleNestedFunctionTestA function whose body is a lambda returning a lambda can be called with all three arguments at once.
- elm / InfixLastOperandAnyExprTestThe last operand of a chain may be any expression: an `if` or a lambda.
- elm / JoinpointABI23Majority3FlatTestChecks a function whose `case` branches each return a lambda for the rest of its arguments, called with all four arguments at once.
- elm / LambdaBoundaryCaptureTestChecks that a lambda nested inside `case` branches refers to the variable it names, not to another binding that appears around it.
- elm / LambdaCaseBoundaryTestChecks functions whose body is a `case` on the first argument that returns a two-parameter lambda in each branch.
- elm / LambdaLetBoundaryTestChecks functions that bind values in a `let` and then return a lambda for their remaining arguments.
- elm / LetBoundLambdaCallTestA two-argument anonymous function bound in a `let` and then applied to two arguments: `(\x y -> x) 1 2` returns the first, 1.
- elm / LetSeparatedStagingTestA function defined with fewer parameters than its annotated type returns, from different `case` branches, lambdas that take the remaining arguments in different groupings.
- elm / ListLiteralDebugLogKindTestValues returned by `Debug.log` keep their value when used in a closure, a tuple, a function argument, a list literal and a `::` cons.
- 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 / LssGapBodyTieAnnoABA top-level function that returns a lambda gives the same result whether or not it has a type annotation.
- 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 / PartialAppCaptureTypesTestTests partial applications that hold a bound `Float`, `Char`, `Bool` or `String` argument and return it when later given the remaining arguments.
- elm / PartialAppChainTestTests a three-argument function partially applied one argument at a time, `addThree 3`, then `4`, then `3`, against a direct full call.
- elm / PartialApplicationTestTests partial application of two-argument functions, both called directly and passed to a local `map`.
- elm / PolyStepLoopFoldMIntTestA monadic fold, `foldM`, built on a polymorphic `Step`-driven state loop, sums a list of `Int`s and threads its state correctly.
- elm / WideClosureSat26TestA function given 26 `Int` arguments at once returns a working one-argument function that still sees all 26 of them.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:d-exp-lambda] 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.