Rule 106d-patrow-field
Pattern Rows
(106)
Comments
The pattern row binds its variable to the field of ; in a row written as a label alone the variable is spelt as the label (Appendix A). The side condition makes the rule apply exactly when has the field; by elaboration it always holds, since a record of the type the pattern requires has every field the pattern row names. Hence a pattern row cannot fail, and its result is a value environment, never FAIL, as rule (104) expects.
TeX source
\defnrule[r:d-patrow-field]
{\lab\in\Dom r\premsep\opt{\jdgv{E}{r}{\patrow}{\VE}}}
{\jdgv{E}{r}{\lab\ \kw{=}\ \var\ \opt{\kw{,}\ \patrow}}{\{\var\mapsto r(\lab)\}\opt{+\,\VE}}}Tests (40)
- elm / AccessorFunctionFieldInListTestRecord accessors for function-typed fields can be used as list elements.
- elm / AccessorFunctionFieldTailCallTestRecord accessors for function-typed fields can be passed as arguments of self-recursive tail calls.
- elm / AccessorPlaceholderAccessorOfAFunctionFieldPassedInTailCallsTestRecord accessors for function-typed fields can be passed as arguments of tail calls, at top level and in an unannotated let-bound function.
- elm / AccessorToLocalFuncTestA record accessor can be passed as an argument to a let-bound function.
- elm / AccessorVariableTestA record accessor works when bound to a variable, and `.name` works on elements of lists of two different record types.
- elm / CaseNestedRecordAccessTestChecks a function that destructures a constructor in its argument and then cases on a looked-up value, calling another function that also destructures a constructor argument and cases on a record 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 / LssGapRecordFnNoAliasA function stored in a field of an unaliased record type is called through that field.
- elm / MinimalRecordPatternTestA record pattern binds the field it names.
- elm / RecordAccessTestDot syntax reads fields of let-bound record literals.
- elm / RecordAccessorFunctionCaseTestA record accessor function `.x` stored in a top-level value can be applied to a record.
- elm / RecordAccessorFunctionTestRecord accessor functions such as `.name` work as arguments to a function.
- elm / RecordNarrow01CapturesNonEmptyTestA let-bound helper with an inferred extensible-record argument, folded over two records with `List.foldl`, reads the right nested field when its `captures` field is a non-empty list.
- elm / RecordNarrow02CapturesNothingTestA let-bound helper with an inferred extensible-record argument, folded over two records with `List.foldl`, reads the right nested field when its `captures` field is `Nothing`.
- elm / RecordNarrow03FullAnnotationTestA let-bound helper annotated with concrete record aliases, folded over two nested records with `List.foldl`, reads the right nested field.
- elm / RecordNarrow04SingleFieldTestA let-bound helper that reads a single field of a nested five-field record, folded with `List.foldl`, gets that field's value.
- elm / RecordNarrow05NoNestingTestA let-bound helper with an inferred extensible-record argument, folded with `List.foldl`, reads the right field of a record that is not nested in another.
- elm / RecordNarrow06RowPolyAnnotationTestA let-bound helper annotated with a nested extensible record type, folded with `List.foldl`, reads the right nested field.
- elm / RecordNarrow08NoDestructureTestA let-bound helper with an inferred extensible-record argument, folded with `List.foldl`, logs a nested custom-type field as `LambdaId 999`.
- elm / RecordNarrow09DirectCallTestA let-bound helper with an inferred extensible-record argument reads the right nested field when called directly.
- elm / RecordNarrow10TripleNestingTestA let-bound helper with an inferred extensible-record argument, folded with `List.foldl`, reads a field three records deep.
- elm / RecordNestedAccessTestChained field access reads through nested record literals two and three levels deep.
- elm / RecordOpenNarrowFieldIndexTestA let-bound helper with an inferred extensible-record argument, folded over two nested records with `List.foldl`, reads the right nested field.
- elm / RecordWithFunctionsTestFunctions stored in record fields can be called, composed and replaced with record update.
- elm / RecursiveTypeInRecordTestChecks that a custom type can recurse through a record carried by one of its constructors.
- 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.
- elm / StandardCoreEvaluationExamplesTestSmall programs for rules of the dynamic semantics of the Core that other tests reach only in passing, and examples from the Comments of A Standard Definition of Elm?, Chapter 6.
- elm / WideRecord33TestA record with 33 fields, cycling through `Int`, `Float`, `Char`, `String` and `Bool`, supports field access, record patterns, update, equality and printing.
- elm / WideRecord40TestA record with 40 fields, cycling through `Int`, `Float`, `Char`, `String` and `Bool`, supports field access, record patterns, update, equality and printing.
- elm / WideRecordPatternTestA record with 28 `Int` fields reads back correctly through field access, through a record pattern, and after a record update.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:d-patrow-field] 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.