Rule 61sm-datbind
Comments
The parameters are made explicit while the constructors elaborate, and are generalised by the closure, since at the top level. A parameter need not occur in , so phantom types are allowed. A parameter used as the extension variable of a record type is a row variable; is then the open record type with no fields of its own, and an argument of in that position is a record type. The side condition gives the custom types of one group distinct type names; rule (57) makes them new. The syntactic restrictions ensure that and .
Referred to from
- The comment on rule
sm-topdec-types(Chapter 5) - Section 5.6 Principal Derivations
- Section 6.2 Number Specialisation
TeX source
\defnrule[r:sm-datbind]
{\tyvarseq = \tyrowvar^{(k)} \premsep U = \{\tyrowvar_1, \cdots, \tyrowvar_k\} \\ \jdg{C + U}{\tyvar_i}{\tau_i} \quad (1 \le i \le k) \\ \jdg{C + U, \tau^{(k)}t}{\conbind}{\VE} \premsep t \in \TyName^{(k)} \\ \opt{\jdg{C}{\datbind'}{\VE', \TE'} \premsep \forall (t', \VE'') \in \Ran\TE',\ t \neq t'}}
{C \vdash \tycon\ \tyvarseq\ \kw{=}\ \conbind\ \opt{\kw{and}\ \datbind'} \Rightarrow \\ \qquad \Clos_C \VE\ \opt{{}+ \VE'},\ \{\tycon \mapsto (t, \Clos_C \VE)\}\ \opt{{}+ \TE'}}Tests (18)
- elm / CaseTreeTestA case expression on a recursive custom type, a binary tree, drives a recursive function that counts the tree's nodes.
- 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 / LetNumberCustomTriple3TestA single-constructor type whose three fields share one type variable, built from number literals in an unannotated `let` and matched by `case` with every field used as a Float: `round 45 + round 60 + round 75` gives 180.
- elm / LetNumberCustomTypeTestA let-bound custom type value whose type parameter is `number`, built from an integer literal, has its payload extracted by `case` and multiplied by a `Float`.
- elm / LetNumberNestedCustomTestAn integer literal nested two custom-type constructors deep is used as a `Float`: `Box (NumBox 30)`, matched by the pattern `Box (NumBox n)` and multiplied by `1.5`, logs 45.
- elm / LetNumberUnionBranchTestInteger literals carried by a constructor of a two-constructor custom type with a `number` type parameter are used as `Float`s: `Pair 30 40`, matched by `Pair a b` and computing `round (a * 1.5 + b * 2.5)`, logs 145.
- 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 / PolyChainCallTestTests a polymorphic function that calls another polymorphic function twice, building a binary tree of two nodes that is then counted.
- elm / RecursiveMutualTypeTestA pair of mutually recursive custom types, `Forest` and `RoseTree`, can be built and traversed.
- elm / RecursiveTreeTestA recursive binary tree type can be summed and measured with recursive functions.
- elm / StandardA98TypeBeforeAliasStringMismatchTestA custom type declared before a local alias spelt like an imported type uses the local alias.
- elm / StandardA98TypeBeforeAliasTestA custom type may mention a local alias declared after it, even one spelt like an imported type.
- elm / TailRecCustomCaseTestA self tail-recursive function that matches on a user-defined list type and destructures its `Cons` constructor gives the right result: summing `Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))` is 10.
- elm / TypeMismatchDifferentlyNamedComparableVarsTestA list of two tuples whose first components are values of different custom types is rejected with a TYPE MISMATCH, where the second components are functions annotated with differently named `comparable` variables.
- elm / TypeMismatchDifferentlyNamedFlexVarsTestA list of two tuples whose first components are values of different custom types is rejected with a TYPE MISMATCH, where the second components are functions annotated with differently named type variables.
- elm / TypeMismatchLocalTypeNamedLikeAnImportedOneTestA local type named `Maybe` is a different type from the core `Maybe`, so mixing them is rejected with a TYPE MISMATCH.
- elm / TypeMismatchTwoComparableVarsTestA list mixing tuples whose first components have different custom types 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:sm-datbind] 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.