Rule 39s-atpat-record
Atomic Patterns
(39)
Comments
The record type may have fields besides those the pattern names, and it may be open: a record pattern matches every record with the fields it names.
TeX source
\defnrule[r:s-atpat-record]
{\opt{\jdg{C}{\patrow}{(\VE, \varrho)}} \premsep \tau \in \RecType \premsep \emptymap\opt{{}+\varrho} \subseteq (\varrho \of \tau)}
{\jdg{C}{\kw{\kwlb}\,\opt{\patrow}\,\kw{\kwrb}}{(\emptymap\opt{{}+\VE},\ \tau)}}Tests (43)
- 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 / CompilerIssue1748DestructureMissingFieldCrashTestDestructuring a record field that does not exist, in an unannotated function, crashes the compiler.
- elm / CompilerIssue2148RecordUpdateFoldrCrashTestA type error in a `foldr` over records must be reported normally, not crash the compiler.
- 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 / LetNumberRecordDestructureTestInteger-literal record fields bound by a let destructuring pattern are used as `Float`s: `{ lo, hi } = { lo = 30, hi = 40 }` followed by `round (lo * 1.5) + round (hi * 1.5)` logs 105.
- 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 / 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 / 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 / RecordOpenNarrowFieldIndexTestA let-bound helper with an inferred extensible-record argument, folded over two nested records with `List.foldl`, reads the right nested field.
- 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 / TypeMismatchAccessOnANumberTestField access on an `Int` is rejected with a TYPE MISMATCH.
- elm / TypeMismatchAccessOnAnEmptyRecordTestReading a field from an empty record is rejected with a TYPE MISMATCH.
- elm / TypeMismatchFieldAccessUnderIntTestA value annotated `Int` but defined as a `String` field of a record, `r.name`, is rejected with a TYPE MISMATCH.
- elm / TypeMismatchFieldTypoTestThe compiler rejects access to a misspelled record field, `r.nmae` on a record whose only field is `name`, with a TYPE MISMATCH error.
- elm / TypeMismatchFlexibleRecordWhereClosedAfterAMismatchTestThe compiler rejects passing a tuple whose two components both disagree with the annotation, with a TYPE MISMATCH error.
- elm / TypeMismatchFlexibleRecordWithAnExtraFieldWhereClosedTestThe compiler rejects passing a record that must have an `age` field to a function that takes exactly `{ name : Int }`, with a TYPE MISMATCH error.
- elm / TypeMismatchMisspeltFieldAmongManyTestAccessing a misspelt field of a record with many fields is rejected with a TYPE MISMATCH.
- elm / TypeMismatchMisspeltFieldOfExtensibleRecordTestA function annotated to take an extensible record with fields `alpha` and `beta` that reads the misspelt field `r.alpah` is rejected with a TYPE MISMATCH error.
- elm / TypeMismatchRecordPatternTestA record pattern on an argument annotated as `Int` is rejected with a TYPE MISMATCH.
- elm / TypeMismatchTwoFlexibleRecordsTestA record argument whose `name` field is used both as a number and as a `String` is rejected with a TYPE MISMATCH.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:s-atpat-record] 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.