Rule 62sm-conbind
Constructor Bindings
(62)
Comments
When the type of is , so a constructor without arguments is a value of the custom type. The syntactic restrictions ensure .
TeX source
\defnrule[r:sm-conbind]
{\jdg{C}{\ty_i}{\tau_i} \quad (1 \le i \le n) \premsep \opt{\jdg{C, \tau}{\conbind'}{\VE}}}
{C, \tau \vdash \con\ \ty_1 \cdots \ty_n\ \opt{\kw{|}\ \conbind'} \Rightarrow \\ \qquad \{\con \mapsto (\tau_1 \rightarrow \cdots \rightarrow \tau_n \rightarrow \tau, \isc)\}\ \opt{{}+ \VE}}Tests (25)
- elm / CustomTypeFuncFieldTestA custom type whose single constructor wraps a function can be unwrapped by an argument pattern and the function called.
- elm / CustomTypeMultiFieldTestA value of a custom type whose constructor has three arguments of different types (`String`, `Int`, `Bool`) can be built and logged.
- elm / CustomTypeNestedTestA value of a recursive, parameterised custom type (a binary tree with values in its leaves) can be built several levels deep and logged.
- elm / EitherTypeTestA custom type with two type parameters and one constructor for each can be built, mapped and pattern-matched.
- elm / EscapeCustomCaseScrutineeTestA value of a user-defined custom type, built in the call and taken apart by a `case` in another function, yields its payload.
- elm / HoleyAliasTwoParamsTestA type alias with two type parameters, used as a constructor field, keeps each parameter bound to its own argument.
- elm / LssGapCtorScaleConstructors of arity one to four build values that pattern matches in function arguments take apart again.
- elm / LssGapCustomTypeFnA function stored in a custom type constructor can be pattern matched out and applied: `useBox (Box double) 7` prints 14.
- elm / PhantomTypeVarTestTests a custom type with a type parameter that one of its constructors does not use, rebuilt at a new type by generic functions.
- elm / RecursiveTypeInRecordTestChecks that a custom type can recurse through a record carried by one of its constructors.
- elm / SingleCtorPairBoolCharTestPattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Char`.
- elm / SingleCtorPairBoolFloatTestPattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Float`.
- elm / SingleCtorPairBoolIntBidiTestPattern matching and value extraction both work on two single-constructor types in one module, one wrapping a `Bool` and one wrapping an `Int`.
- elm / SingleCtorPairCharFloatTestValues are extracted correctly from two single-constructor types in one module, one wrapping a `Char` and one wrapping a `Float`.
- elm / SingleCtorPairCharIntTestValues are extracted correctly from two single-constructor types in one module, one wrapping a `Char` and one wrapping an `Int`.
- elm / SingleCtorPairFloatBoolTestPattern matching works on two single-constructor types in one module, one wrapping a `Float` and one wrapping a `Bool`.
- elm / SingleCtorPairIntFloatTestValues are extracted correctly from two single-constructor types in one module, one wrapping an `Int` and one wrapping a `Float`.
- elm / SingleCtorPairStringBoolTestPattern matching works on two single-constructor types in one module, one wrapping a `String` and one wrapping a `Bool`.
- elm / SingleCtorPairStringIntTestValues are extracted correctly from two single-constructor types in one module, one wrapping a `String` and one wrapping an `Int`.
- elm / SingleCtorPairUnitIntTestPattern matching works on two single-constructor types in one module, one wrapping the unit value `()` and one wrapping an `Int`.
- elm / TooManyArgsTooManyArgumentsToANullaryConstructorTestA constructor with no arguments applied to one is rejected with a TOO MANY ARGS error.
- elm / TypeMismatchArgumentToAConstructorTestA constructor applied to an argument of the wrong type is rejected with a TYPE MISMATCH.
- elm / UserBoolNamedCtorTestA custom type may name its own constructors `True` and `False`, and they behave as ordinary constructors, distinct from each other and from `Unknown`.
- elm / WideCtorField24TestA custom type constructor with 27 fields, 25 `Int`s followed by a `Float` and a `Char`, keeps every field, and pattern matching reads back the later ones.
- elm / WideCtorMixedTestA custom type constructor with 60 fields, cycling through `Int`, `Float`, `Char`, `String` and `Bool`, supports pattern matching, equality and printing.
Discussions
Discuss this rule·Search the discussions on GitHub
Discussions are on GitHub; one about this rule has [r:sm-conbind] 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.