Elm Exactly

Rule 62sm-conbind

Constructor BindingsC,τ⊢conbind⇒VE\jdg{C, \tau}{\conbind}{\VE}
C⊢tyi⇒τi(1≤i≤n)⟨C,τ⊢conbind′⇒VE⟩C,τ⊢con ty1⋯tyn ⟨| conbind′⟩⇒{con↦(τ1→⋯→τn→τ,c)} ⟨+VE⟩\frac{\begin{array}{c}\jdg{C}{\ty_i}{\tau_i} \quad (1 \le i \le n) \premsep \opt{\jdg{C, \tau}{\conbind'}{\VE}}\end{array}}{\begin{array}{c}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}\end{array}}
(62)
Read it in its chapter·Permanent address: /standard/rules/sm-conbind

Comments

When n=0n = 0 the type of con\con is τ\tau, so a constructor without arguments is a value of the custom type. The syntactic restrictions ensure con∉Dom VE\con \notin \Dom\VE.

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 / CustomTypeFuncFieldTest
    A custom type whose single constructor wraps a function can be unwrapped by an argument pattern and the function called.
  • elm / CustomTypeMultiFieldTest
    A value of a custom type whose constructor has three arguments of different types (`String`, `Int`, `Bool`) can be built and logged.
  • elm / CustomTypeNestedTest
    A value of a recursive, parameterised custom type (a binary tree with values in its leaves) can be built several levels deep and logged.
  • elm / EitherTypeTest
    A custom type with two type parameters and one constructor for each can be built, mapped and pattern-matched.
  • elm / EscapeCustomCaseScrutineeTest
    A value of a user-defined custom type, built in the call and taken apart by a `case` in another function, yields its payload.
  • elm / HoleyAliasTwoParamsTest
    A type alias with two type parameters, used as a constructor field, keeps each parameter bound to its own argument.
  • elm / LssGapCtorScale
    Constructors of arity one to four build values that pattern matches in function arguments take apart again.
  • elm / LssGapCustomTypeFn
    A function stored in a custom type constructor can be pattern matched out and applied: `useBox (Box double) 7` prints 14.
  • elm / PhantomTypeVarTest
    Tests a custom type with a type parameter that one of its constructors does not use, rebuilt at a new type by generic functions.
  • elm / RecursiveTypeInRecordTest
    Checks that a custom type can recurse through a record carried by one of its constructors.
  • elm / SingleCtorPairBoolCharTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Char`.
  • elm / SingleCtorPairBoolFloatTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `Bool` and one wrapping a `Float`.
  • elm / SingleCtorPairBoolIntBidiTest
    Pattern matching and value extraction both work on two single-constructor types in one module, one wrapping a `Bool` and one wrapping an `Int`.
  • elm / SingleCtorPairCharFloatTest
    Values are extracted correctly from two single-constructor types in one module, one wrapping a `Char` and one wrapping a `Float`.
  • elm / SingleCtorPairCharIntTest
    Values are extracted correctly from two single-constructor types in one module, one wrapping a `Char` and one wrapping an `Int`.
  • elm / SingleCtorPairFloatBoolTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `Float` and one wrapping a `Bool`.
  • elm / SingleCtorPairIntFloatTest
    Values are extracted correctly from two single-constructor types in one module, one wrapping an `Int` and one wrapping a `Float`.
  • elm / SingleCtorPairStringBoolTest
    Pattern matching works on two single-constructor types in one module, one wrapping a `String` and one wrapping a `Bool`.
  • elm / SingleCtorPairStringIntTest
    Values are extracted correctly from two single-constructor types in one module, one wrapping a `String` and one wrapping an `Int`.
  • elm / SingleCtorPairUnitIntTest
    Pattern matching works on two single-constructor types in one module, one wrapping the unit value `()` and one wrapping an `Int`.
  • elm / TooManyArgsTooManyArgumentsToANullaryConstructorTest
    A constructor with no arguments applied to one is rejected with a TOO MANY ARGS error.
  • elm / TypeMismatchArgumentToAConstructorTest
    A constructor applied to an argument of the wrong type is rejected with a TYPE MISMATCH.
  • elm / UserBoolNamedCtorTest
    A custom type may name its own constructors `True` and `False`, and they behave as ordinary constructors, distinct from each other and from `Unknown`.
  • elm / WideCtorField24Test
    A 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 / WideCtorMixedTest
    A 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.