Rule 93d-valbind-pat
Value Bindings
(93)
Comments
There is no rule in which , matched against , gives FAIL: the static semantics requires the pattern of a value binding to be exhaustive (Chapter 4).
TeX source
\defnrule[r:d-valbind-pat]
{\jdg{E}{\expm}{v}\premsep\jdgv{E}{v}{\atpat}{\VE}}
{\jdg{E}{\atpat\ \kw{=}\ \expm}{\VE}}Tests (31)
- elm / CharAstralTupleTestAn astral `Char` (code point above 0xFFFF) in a pair and in a 3-tuple keeps its code point when read back with a tuple pattern, in a function's argument and in a destructuring `let`. How `Debug.log` prints such tuples is checked by `CharAstralTupleShowTest`.
- elm / ClosureCaptureTupleTestA lambda returned from a function captures a tuple and destructures it with a `let` pattern when called.
- elm / CovLambdaSetFunctionsDestructuredFromTuplesAndRecordsTestLambdas taken out of a tuple and a record by destructuring `let` patterns, put in a list and applied in turn.
- elm / DeepNestStressTestDeeply nested lists, tuples, records and `let` expressions can be built and taken apart.
- 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 / EdgeCaseAllDestructPatternsTest`let` bindings destructure a tuple, a record, a tuple returned by a `case`, and an `as` pattern, and each bound name has the expected value.
- 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 / EmbeddedNothingInTupleTestA tuple pattern in a `let` takes `Nothing` and `Just 42` back out of a pair, and each matches the right pattern.
- elm / EmbeddedUnitCaptureTestA local function returns a tuple containing a unit value bound in the enclosing `let`, and the tuple is destructured by a pattern.
- elm / EscapeTopLevelTupleTestA tuple defined as a top-level constant is destructured in a `let` pattern into its two components.
- 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 / 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 / LetDestructAliasTestA `let` destructuring with an `as` pattern binds both the parts and the whole: from `((a, b)) as pair = (1, 2)`, `pair` is `(1,2)` and `a` is 1.
- elm / LetDestructFuncTupleTestA `let` destructures a pair of functions chosen by a `case`: a field accessor and a record-update lambda for the same field.
- elm / LetDestructRecordTestRecord patterns in `let` bindings: a single field, two fields, a subset of a record's fields (`{ p, r }` from a record that also has `q`), and a record pattern nested inside a tuple pattern.
- elm / LetDestructTupleNestedTestTuple patterns in `let` bindings: a flat pair, a pair of pairs destructured in one pattern, and a pair whose second part is bound by name and destructured by a later binding.
- elm / LetDestructuringTestTuple patterns in `let` bindings, for a pair and for a triple; the line labelled `head` logs the first element of the triple `(10, 20, 30)`.
- elm / LssGapTupleFnA function stored in a tuple is taken out by destructuring and called.
- elm / MinimalDestructuringTestA let definition by a tuple pattern.
- elm / StandardA99RecordPatternAsTestA record pattern under `as` in a `let` binding.
- elm / StandardA99RecordPatternBothTestA variable bound by a record pattern in a `let`, used at Int and at Float.
- elm / StandardA99RecordPatternDependentTestA `let` definition that uses a variable bound by a record pattern.
- elm / StandardA99RecordPatternFloatTestA variable bound by a record pattern in a `let`, used at Float.
- elm / StandardA99RecordPatternFunctionTestA function bound by a record pattern in a `let`, applied at Int and at Float.
- elm / StandardA99RecordPatternInTopCopyTestA record pattern in a `let` inside a top-level value that is itself copied.
- elm / StandardA99RecordPatternInTupleTestA record pattern inside the tuple pattern of a `let` binding.
- elm / StandardA99RecordPatternIntTestA variable bound by a record pattern in a `let`, used at Int.
- elm / StandardA99RecordPatternLambdaTestA record pattern in a lambda inside a `let` binding that is copied.
- elm / StandardA99RecordPatternSharedVariableTestTwo variables of one record pattern that share one `number` type.
- elm / StandardA99RecordPatternTwoVariablesTestTwo variables of one record pattern, with independent `number` types, used at opposite types.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:d-valbind-pat] 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.