Rule 44s-pat-cons
Patterns
(44)
Comments
The type name is of the initial basis, whatever the program binds to List.
TeX source
\defnrule[r:s-pat-cons]
{\jdg{C}{\pat_1}{(\VE_1, \tau)} \premsep \jdg{C}{\pat_2}{(\VE_2, \tau\,\tList)}}
{\jdg{C}{\pat_1\ \kw{::}\ \pat_2}{(\VE_1 + \VE_2,\ \tau\,\tList)}}Tests (5)
- elm / CaseListConsTestChecks that a recursive function matching a list against `[]` and `x :: xs` sums the empty list, a one-element list and a three-element list correctly.
- elm / MinimalConsPatternTestA list construction pattern matches a non-empty list.
- elm / TypeMismatchConsHeadAgainstAConsTailTestA list pattern `1 :: "s" :: rest` is rejected with a TYPE MISMATCH, because it asks for a number and a `String` as elements of the same list.
- elm / TypeMismatchListEntryPatternTestA list pattern whose entries have different types is rejected with a TYPE MISMATCH.
- elm / TypeMismatchTailPatternTestA list pattern whose tail is a `String` literal 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-pat-cons] 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.