Elm Exactly

Rule 63sm-typbind

Alias BindingsC⊢typbind⇒VE,TE\jdg{C}{\typbind}{\VE, \TE}
tyvarseq=ξ(k)C+{ξ1,⋯ ,ξk}⊢ty⇒τty∉Dom labsC⊢tycon tyvarseq = ty⇒{}, {tycon↦(Λξ(k).τ,{})}\frac{\begin{array}{c}\tyvarseq = \tyrowvar^{(k)} \premsep \jdg{C + \{\tyrowvar_1, \cdots, \tyrowvar_k\}}{\ty}{\tau} \premsep \ty \notin \Dom\smlabs\end{array}}{\begin{array}{c}\jdg{C}{\tycon\ \tyvarseq\ \kw{=}\ \ty}{\emptymap,\ \{\tycon \mapsto (\Lambda\tyrowvar^{(k)}.\tau, \emptymap)\}}\end{array}}
(63)
Read it in its chapter·Permanent address: /standard/rules/sm-typbind

Comments

An alias generates no type name: it denotes a type function, and a type expression that applies it denotes the expansion (rule (28)). Thus after type alias Id = Int, the types Id and Int are the same type. By the syntactic restrictions the parameters are exactly the type variables of ty\ty, so the type function has no unused parameter. Rules (63) and (64) both cover the production; which applies is decided by the form of ty\ty. An alias of an extensible record type, or of another alias, defines no constructor, even when that alias is a record alias.

Referred to from

TeX source
\defnrule[r:sm-typbind]
  {\tyvarseq = \tyrowvar^{(k)} \premsep \jdg{C + \{\tyrowvar_1, \cdots, \tyrowvar_k\}}{\ty}{\tau} \premsep \ty \notin \Dom\smlabs}
  {\jdg{C}{\tycon\ \tyvarseq\ \kw{=}\ \ty}{\emptymap,\ \{\tycon \mapsto (\Lambda\tyrowvar^{(k)}.\tau, \emptymap)\}}}

Tests (18)

  • elm / CompilerIssue1916PhantomExtensibleAliasCrashTest
    A phantom type over an extensible record in a function alias crashes the compiler.
  • elm / CompilerIssue2019AliasOfTypeVariableTest
    An alias `MyType k = k` is not interchangeable with `k` in a result position.
  • elm / CompilerIssue2182ExtensibleFunctionAliasCrashTest
    An alias that extends its parameter with a field the parameter already has is not a type.
  • elm / CompilerIssue2252IdentityAliasTest
    A type alias `Identity a = a` is interchangeable with `a`, so `map change = change` type-checks against `(a -> b) -> Identity a -> Identity b`.
  • elm / CompilerIssue2298IdentityAliasResultTest
    A type alias `Msg a = a` in an annotation's result is interchangeable with `a`, so `make = identity` type-checks against `a -> Msg a`.
  • elm / CovEtaDebugLogTest
    Checks a function defined with fewer parameters than its annotated type: `mk : Int -> Fn`, where `Fn` is an alias of `Int -> Int`, takes one parameter and returns a `let`-bound function whose body calls `Debug.log`.
  • elm / CovForeignTypesTest
    Checks the use of two values from another module of the same project: `secretValue`, whose annotation names a type alias that its module does not expose, and a field of `config`, read through the module name as `CovForeignTypesHelper.config.x`. Their sum, 42, is logged.
  • elm / CovLambdaBoundaryCaseBoundaryUnderAFunctionAliasTest
    A function whose result type is a type alias for a function type, with a `case` that returns a different lambda per branch.
  • elm / EtaExpandStateFunctionSequenceTest
    A state-passing `sequence` written with `andThen` and `pure` over a function type alias, `St a = Int -> a`, whose definitions take more parameters than their annotations show.
  • elm / EtaExpandStateTest
    A state monad over the function alias `St a = Int -> ( Int, a )`, with `sequence` written recursively using `andThen` and `pure`, threads its state correctly.
  • elm / HoleyAliasTwoParamsTest
    A type alias with two type parameters, used as a constructor field, keeps each parameter bound to its own argument.
  • elm / PolyStepLoopFloatResultTest
    A polymorphic state-threading loop, driven by a `Step state a` custom type, returns a `Float` result and the threaded state correctly.
  • elm / PolyStepLoopFoldMIntTest
    A monadic fold, `foldM`, built on a polymorphic `Step`-driven state loop, sums a list of `Int`s and threads its state correctly.
  • elm / StandardA98TypeBeforeAliasTest
    A custom type may mention a local alias declared after it, even one spelt like an imported type.
  • elm / TypeMismatchAliasNamedLikeAnImportedTypeTest
    A local type alias that shadows an imported type name is a different type from it, so mixing the two is rejected with a TYPE MISMATCH.
  • elm / TypeMismatchImportedTypeNamedLikeAnAliasTest
    The compiler rejects a list holding both `Basics.True` and a value of a local alias named `Bool`, which stands for `Int`, with a TYPE MISMATCH error.
  • elm / TypeMismatchTupleAgainstAnAliasTest
    A list holding a value of an alias for `Int` and a tuple is rejected with a TYPE MISMATCH.
  • elm / TypeMismatchTypeWhereAnAliasTest
    A value annotated with a type alias of `Int` but defined as a `String` is rejected with a TYPE MISMATCH error.

Discussions

Discuss this rule·Search the discussions on GitHub

Discussions are on GitHub; one about this rule has [r:sm-typbind] 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.