Rule 63sm-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 , so the type function has no unused parameter. Rules (63) and (64) both cover the production; which applies is decided by the form of . 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 / CompilerIssue1916PhantomExtensibleAliasCrashTestA phantom type over an extensible record in a function alias crashes the compiler.
- elm / CompilerIssue2019AliasOfTypeVariableTestAn alias `MyType k = k` is not interchangeable with `k` in a result position.
- elm / CompilerIssue2182ExtensibleFunctionAliasCrashTestAn alias that extends its parameter with a field the parameter already has is not a type.
- elm / CompilerIssue2252IdentityAliasTestA type alias `Identity a = a` is interchangeable with `a`, so `map change = change` type-checks against `(a -> b) -> Identity a -> Identity b`.
- elm / CompilerIssue2298IdentityAliasResultTestA type alias `Msg a = a` in an annotation's result is interchangeable with `a`, so `make = identity` type-checks against `a -> Msg a`.
- elm / CovEtaDebugLogTestChecks 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 / CovForeignTypesTestChecks 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 / CovLambdaBoundaryCaseBoundaryUnderAFunctionAliasTestA function whose result type is a type alias for a function type, with a `case` that returns a different lambda per branch.
- elm / EtaExpandStateFunctionSequenceTestA 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 / EtaExpandStateTestA state monad over the function alias `St a = Int -> ( Int, a )`, with `sequence` written recursively using `andThen` and `pure`, threads its state correctly.
- elm / HoleyAliasTwoParamsTestA type alias with two type parameters, used as a constructor field, keeps each parameter bound to its own argument.
- elm / PolyStepLoopFloatResultTestA polymorphic state-threading loop, driven by a `Step state a` custom type, returns a `Float` result and the threaded state correctly.
- elm / PolyStepLoopFoldMIntTestA monadic fold, `foldM`, built on a polymorphic `Step`-driven state loop, sums a list of `Int`s and threads its state correctly.
- elm / StandardA98TypeBeforeAliasTestA custom type may mention a local alias declared after it, even one spelt like an imported type.
- elm / TypeMismatchAliasNamedLikeAnImportedTypeTestA 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 / TypeMismatchImportedTypeNamedLikeAnAliasTestThe 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 / TypeMismatchTupleAgainstAnAliasTestA list holding a value of an alias for `Int` and a tuple is rejected with a TYPE MISMATCH.
- elm / TypeMismatchTypeWhereAnAliasTestA 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.