Rule 81d-app-closure
Application of Values
(81)
Comments
There is no rule in which , matched against , 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 / 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 / CaseInLambdaTestChecks 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 / 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 / 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 / CombinatorBComposeTestThe B combinator, function composition, built only from S and K: `b square inc 4` is `square (inc 4)`, which is 25.
- elm / CombinatorBSumMapTestThe 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 / CombinatorCConsTestThe 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 / CombinatorCFlipTestThe C combinator, which swaps two arguments, built from S and K: `c sub 10 3` is `sub 3 10`, which is -7.
- elm / CombinatorIIdentityTestThe I combinator, identity, written as `s k k`: `i 42` is 42.
- elm / CombinatorListStringTestSKI-style combinators applied to lists, strings and functions over them, each printing its result.
- elm / CombinatorPLengthsTestThe P combinator, which applies one function to two arguments and combines the results: `p (+) length [ 1, 2, 3 ] [ 4, 5 ]` is 5.
- elm / CombinatorRefIdentityBugTestA 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 / CombinatorSFeedTestThe 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 / CombinatorSPalindromeTestThe S combinator with a one-argument string function: `s (++) bang "straw"` is `"straw" ++ bang "straw"`, which is `"strawstraw!"`.
- elm / CombinatorSpCombineTestThe 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 / CombinatorSpMulTestThe SP combinator with operator sections as its functions: `sp (*) ((+) 1) ((*) 2) 6` is `7 * 12`, which is 84.
- elm / CombinatorStdlibTCombinatorPipeListIntoComposedOpsTestThe 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 / CombinatorTPipeTestThe T combinator, built from S and K, passing `[ 1, 2, 3 ]` to the composition of `sum` and `map ((*) 2)`: the result is 12.
- elm / CombinatorTThrushTestThe T combinator, which applies its second argument to its first, built from S and K: `t 7 (\x -> x * 3)` is 21.
- elm / CombinatorTestSKI-style combinators, most of them built from S and K, each applied to `Int` arguments and printing its result.
- elm / CombinatorWConcatTestThe W combinator, which passes one argument twice, applied to string append: `w (++) "hi"` is `"hihi"`.
- elm / CombinatorWDupTestThe W combinator, which passes one argument twice: `w mul 9` is `mul 9 9`, which is 81.
- 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 / CovEtaDebugLogTestChecks 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 / CovLambdaSetFunctionsInRecordsTuplesAndMaybeTestFunctions stored in record fields, tuples and a `Maybe`, taken out again and applied.
- elm / DestructCaptureTestA tuple pattern in a `let` inside one function does not interfere with a same-named variable in the function that calls it.
- 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 / EtaExpandStateTestA state monad over the function alias `St a = Int -> ( Int, a )`, with `sequence` written recursively using `andThen` and `pure`, threads its state correctly.
- elm / FlipFunctionTestA locally defined, annotated `flip` swaps the two arguments of the function it is given.
- elm / FunctionBasicTestSimple unannotated top-level functions of one and two arguments return the right values.
- 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 / FunctionValuesChosenByIfCaseAndTupleTestFunctions chosen at run time by `if`, `case` and a returned tuple are called correctly.
- 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 / HigherOrderTestSimple higher-order functions apply their function argument the right number of times.
- elm / HigherOrderTripleNestedFunctionTestA function whose body is a lambda returning a lambda can be called with all three arguments at once.
- elm / IndirectCallFloatTestFunctions of type `Float -> Float` passed to higher-order functions, including one built with `>>`, return the right Float values.
- 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 / LambdaPatternArgTestChecks anonymous functions whose parameters are tuple, record and wildcard patterns.
- 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 / LetMultiFuncTestTwo 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 / 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 / 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 / PapEtaCtorProbeTests point-free top-level functions defined by partially applying a two-argument function, stored in a constructor, pattern-matched back out and applied.
- 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 / PolyEscapePolymorphicFunctionExtractedFromTupleTestA 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 / StandardA99RecordPatternSharedVariableTestTwo variables of one record pattern that share one `number` type.
- elm / WideClosureSat26TestA 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 / CompositionTestFunction composition with `>>` and `<<`, and the pipe operator `|>`.
- elm-core / PipelineTestTests 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.