Elm Exactly

Rule 81d-app-closure

Application of Values⊢v1 v2⇒v\japp{v_1}{v_2}{v}
E+Rec VE,v⊢atpat⇒VE′E+Rec VE+VE′⊢exp⇒v′⊢(atpat,exp,E,VE) v⇒v′\frac{\begin{array}{c}\jdgv{E+\Rec\VE}{v}{\atpat}{\VE'}\premsep \jdg{E+\Rec\VE+\VE'}{\expm}{v'}\end{array}}{\begin{array}{c}\japp{(\atpat,\expm,E,\VE)}{v}{v'}\end{array}}
(81)
Read it in its chapter·Permanent address: /standard/rules/d-app-closure

Comments

There is no rule in which atpat\atpat, matched against vv, gives FAIL: the static semantics requires the pattern of a lambda to be exhaustive (Chapter 4). Were it to fail, no rule would apply.

TeX source
\defnrule[r:d-app-closure]
  {\jdgv{E+\Rec\VE}{v}{\atpat}{\VE'}\premsep
   \jdg{E+\Rec\VE+\VE'}{\expm}{v'}}
  {\japp{(\atpat,\expm,E,\VE)}{v}{v'}}

Tests (78)

  • 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 / CaseInLambdaTest
    Checks that a `case` expression on a `Bool` inside an anonymous function evaluates correctly, both when the lambda is bound to a name and when it is passed straight to another 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 / 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 / CombinatorBComposeTest
    The B combinator, function composition, built only from S and K: `b square inc 4` is `square (inc 4)`, which is 25.
  • elm / CombinatorBSumMapTest
    The B combinator, built from S and K, composing `sum` with a partially applied `map`: the sum of `[ 1, 2, 3 ]` each plus one is 9.
  • elm / CombinatorCConsTest
    The C combinator, which swaps two arguments, built from S and K and applied to the cons operator: `c (::) [ 2, 3 ] 1` is `1 :: [ 2, 3 ]`.
  • elm / CombinatorCFlipTest
    The C combinator, which swaps two arguments, built from S and K: `c sub 10 3` is `sub 3 10`, which is -7.
  • elm / CombinatorIIdentityTest
    The I combinator, identity, written as `s k k`: `i 42` is 42.
  • elm / CombinatorListStringTest
    SKI-style combinators applied to lists, strings and functions over them, each printing its result.
  • elm / CombinatorPLengthsTest
    The P combinator, which applies one function to two arguments and combines the results: `p (+) length [ 1, 2, 3 ] [ 4, 5 ]` is 5.
  • elm / CombinatorRefIdentityBugTest
    A B combinator defined with all its arguments, `b f g y = s (k s) k f g y`, used in the same program as a separate application of `s` to a different function: `b square inc 4` must still be `square (inc 4)`, which is 25.
  • elm / CombinatorSFeedTest
    The S combinator, which gives its argument to a function together with a second function's result on that argument: `s (+) double 5` is `5 + double 5`, which is 15.
  • elm / CombinatorSPalindromeTest
    The S combinator with a one-argument string function: `s (++) bang "straw"` is `"straw" ++ bang "straw"`, which is `"strawstraw!"`.
  • elm / CombinatorSpCombineTest
    The SP combinator, which applies two functions to the same argument and combines the results: `sp mul inc double 6` is `inc 6 * double 6`, which is 84.
  • elm / CombinatorSpMulTest
    The SP combinator with operator sections as its functions: `sp (*) ((+) 1) ((*) 2) 6` is `7 * 12`, which is 84.
  • elm / CombinatorStdlibTCombinatorPipeListIntoComposedOpsTest
    The T combinator, built from S and K inside a `let`, passing `[ 1, 2, 3 ]` to the composition of a sum and a doubling map: the result is 12.
  • elm / CombinatorTPipeTest
    The T combinator, built from S and K, passing `[ 1, 2, 3 ]` to the composition of `sum` and `map ((*) 2)`: the result is 12.
  • elm / CombinatorTThrushTest
    The T combinator, which applies its second argument to its first, built from S and K: `t 7 (\x -> x * 3)` is 21.
  • elm / CombinatorTest
    SKI-style combinators, most of them built from S and K, each applied to `Int` arguments and printing its result.
  • elm / CombinatorWConcatTest
    The W combinator, which passes one argument twice, applied to string append: `w (++) "hi"` is `"hihi"`.
  • elm / CombinatorWDupTest
    The W combinator, which passes one argument twice: `w mul 9` is `mul 9 9`, which is 81.
  • 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 / CovEtaDebugLogTest
    Checks a function defined with fewer parameters than its annotated type: `mk : Int -> Fn`, where `Fn` is an alias of `Int -> Int`, takes one parameter and returns a `let`-bound function whose body calls `Debug.log`.
  • elm / CovLambdaSetFunctionsInRecordsTuplesAndMaybeTest
    Functions stored in record fields, tuples and a `Maybe`, taken out again and applied.
  • elm / DestructCaptureTest
    A tuple pattern in a `let` inside one function does not interfere with a same-named variable in the function that calls it.
  • 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 / EtaExpandStateTest
    A state monad over the function alias `St a = Int -> ( Int, a )`, with `sequence` written recursively using `andThen` and `pure`, threads its state correctly.
  • elm / FlipFunctionTest
    A locally defined, annotated `flip` swaps the two arguments of the function it is given.
  • elm / FunctionBasicTest
    Simple unannotated top-level functions of one and two arguments return the right values.
  • 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 / FunctionValuesChosenByIfCaseAndTupleTest
    Functions chosen at run time by `if`, `case` and a returned tuple are called correctly.
  • 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 / HigherOrderTest
    Simple higher-order functions apply their function argument the right number of times.
  • elm / HigherOrderTripleNestedFunctionTest
    A function whose body is a lambda returning a lambda can be called with all three arguments at once.
  • elm / IndirectCallFloatTest
    Functions of type `Float -> Float` passed to higher-order functions, including one built with `>>`, return the right Float values.
  • 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 / LambdaPatternArgTest
    Checks anonymous functions whose parameters are tuple, record and wildcard patterns.
  • 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 / LetMultiFuncTest
    Two named functions defined in one `let` and called from later bindings: a local `identity` returns its argument (1) and a local `const` returns the first of two (2).
  • 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 / 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 / PapEtaCtorProbe
    Tests point-free top-level functions defined by partially applying a two-argument function, stored in a constructor, pattern-matched back out and applied.
  • 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 / PolyEscapePolymorphicFunctionExtractedFromTupleTest
    A function stored in a tuple and taken out again by a let-bound pattern-matching helper can be applied: `first ( id, 0 ) 42` evaluates to 42.
  • elm / StandardA99RecordPatternSharedVariableTest
    Two variables of one record pattern that share one `number` type.
  • elm / WideClosureSat26Test
    A function given 26 `Int` arguments at once returns a working one-argument function that still sees all 26 of them.
  • elm-core / CharToCodeThroughFunctionTest
    `Char.toCode` of a character returned from a top-level function, here an identity function applied to `'A'`, gives 65.
  • elm-core / CompositionTest
    Function composition with `>>` and `<<`, and the pipe operator `|>`.
  • elm-core / PipelineTest
    Tests the pipeline operators `|>` and `<|`: a chain of forward pipes, a forward pipe into a partially applied local `map`, written with patterns, and a chain of backward pipes.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:d-app-closure] 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.