Elm Exactly

Rule 79d-exp-lambda

ExpressionsE⊢exp⇒v\jdg{E}{\expm}{v}
E⊢\ atpat -> exp⇒(atpat,exp,E,{})\frac{\begin{array}{c}\end{array}}{\begin{array}{c}\jdg{E}{\kw{\textbackslash}\,\atpat\ \kw{->}\ \expm}{(\atpat,\expm,E,\emptymap)}\end{array}}
(79)
Read it in its chapter·Permanent address: /standard/rules/d-exp-lambda

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 EE 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 / AnonymousFunctionTest
    Anonymous functions work as the function argument of higher-order functions.
  • elm / CapturedStagedFuncCallTest
    A 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 / CaseReturnFunctionTest
    Checks 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 / CaseReturningLambdaTest
    Checks 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 / CharAstralClosureCaptureTest
    An 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 / CharCaptureEscapedTailDefTest
    A 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 / ClosureCapture01Test
    A lambda returned from a function captures a single-constructor custom-type argument and unwraps it with `case` when called.
  • elm / ClosureCapture02Test
    A lambda returned from a function captures a `Maybe String` argument and matches on it with `case` when called.
  • elm / ClosureCapture03Test
    A 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 / ClosureCapture04Test
    A 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 / ClosureCapture05Test
    A 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 / ClosureCaptureBoolTest
    Partially applying a `Bool -> Int -> Int` function to a `Bool` gives a function that remembers that `Bool`.
  • elm / ClosureCaptureRecordTest
    A 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 / ClosureCaptureTupleTest
    A lambda returned from a function captures a tuple and destructures it with a `let` pattern when called.
  • elm / ClosureDifferentClosuresPerIfBranchInsideACaseTest
    A 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 / CompilerIssue1813TcoClosureCapturesMutatedArgTest
    A lambda created in a self tail call keeps the argument value of its own call.
  • elm / CompilerIssue2017TcoContinuationShadowedTest
    A lambda passed in a self tail call must call the original continuation, not itself.
  • elm / CompilerIssue2221TcoContinuationTest
    A tail-recursive function that builds a continuation on each call computes `g 5 identity` as 120.
  • elm / CompilerIssue2268TcoClosureCaptureTest
    Lambdas created inside a tail-recursive function each keep the argument value they were created with.
  • elm / CovLambdaBoundaryCaseBoundaryUnderAFunctionAliasTest
    A function whose result type is a type alias for a function type, with a `case` that returns a different lambda per branch.
  • elm / DictMapStagedCaptureTest
    A 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 / EmbeddedEmptyStringCaptureTest
    A 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 / EmbeddedNilCaptureTest
    A local function that refers to an empty list defined in the enclosing `let` matches it against the `[]` pattern.
  • elm / EmbeddedNothingCaptureTest
    A local function that refers to a `Nothing` defined in the enclosing `let` matches it against the `Nothing` pattern.
  • elm / FunctionChainedPartialApplicationTest
    Partially applying a three-argument lambda twice, one argument at a time, gives a function, which `Debug.log` prints as `<function>`.
  • elm / FunctionMultiArgTest
    Unannotated top-level functions of three, four and five arguments return the sum of their arguments.
  • elm / FunctionValueChoiceTest
    Top-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 / HOParamApplyTwoTest
    A let-bound higher-order function that applies its function parameter to two arguments works with a two-parameter lambda.
  • elm / HeteroClosureIntFloatTest
    Partial 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 / HigherOrderFunctionChosenByIfTest
    A higher-order function chosen by an `if` and then applied to a function argument gives the right result.
  • elm / HigherOrderFunctionFactoryTest
    A let-bound function that returns a lambda capturing its argument produces a working function.
  • elm / HigherOrderReturnLambdaBasedOnConditionTest
    A 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 / HigherOrderTripleNestedFunctionTest
    A function whose body is a lambda returning a lambda can be called with all three arguments at once.
  • elm / InfixLastOperandAnyExprTest
    The last operand of a chain may be any expression: an `if` or a lambda.
  • elm / JoinpointABI23Majority3FlatTest
    Checks a function whose `case` branches each return a lambda for the rest of its arguments, called with all four arguments at once.
  • elm / LambdaBoundaryCaptureTest
    Checks that a lambda nested inside `case` branches refers to the variable it names, not to another binding that appears around it.
  • elm / LambdaCaseBoundaryTest
    Checks functions whose body is a `case` on the first argument that returns a two-parameter lambda in each branch.
  • elm / LambdaLetBoundaryTest
    Checks functions that bind values in a `let` and then return a lambda for their remaining arguments.
  • elm / LetBoundLambdaCallTest
    A two-argument anonymous function bound in a `let` and then applied to two arguments: `(\x y -> x) 1 2` returns the first, 1.
  • elm / LetSeparatedStagingTest
    A function defined with fewer parameters than its annotated type returns, from different `case` branches, lambdas that take the remaining arguments in different groupings.
  • elm / ListLiteralDebugLogKindTest
    Values returned by `Debug.log` keep their value when used in a closure, a tuple, a function argument, a list literal and a `::` cons.
  • elm / LocalRecCaptureBoolTest
    A let-bound recursive function reads a Bool defined earlier in the same `let`, and the loop takes the step size that Bool selects.
  • elm / LocalRecCaptureKindsTest
    A 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 / LocalRecCaptureSplitParamTest
    A let-bound recursive function reads a tuple parameter of the tail-recursive function that encloses it.
  • elm / LssGapBodyTieAnnoAB
    A top-level function that returns a lambda gives the same result whether or not it has a type annotation.
  • elm / MutualLetRecManyCapturesTest
    Two 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 / MutualLetRecNestedTest
    Two 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 / PartialAppCaptureTypesTest
    Tests partial applications that hold a bound `Float`, `Char`, `Bool` or `String` argument and return it when later given the remaining arguments.
  • elm / PartialAppChainTest
    Tests a three-argument function partially applied one argument at a time, `addThree 3`, then `4`, then `3`, against a direct full call.
  • elm / PartialApplicationTest
    Tests partial application of two-argument functions, both called directly and passed to a local `map`.
  • elm / PolyStepLoopFoldMIntTest
    A monadic fold, `foldM`, built on a polymorphic `Step`-driven state loop, sums a list of `Int`s and threads its state correctly.
  • elm / WideClosureSat26Test
    A 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.