Elm Exactly
Results / elm /

CustomTypeUnboundVariableTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:restriction modules-custom-type-tyvars

Not translated into Lean for the mechanisation of the book: see why.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
A custom type's constructors use only the type's parameters.

A Standard Definition of Elm?, restriction modules-custom-type-tyvars: every type variable occurring
in the constructors of a custom type is one of its parameters. `a` is not.
<https://elm-test-suite.netlify.app/standard/restrictions/modules-custom-type-tyvars>

Results

elm-0.19.1

pass
Output
Compiling ...-- UNBOUND TYPE VARIABLE ----------------- src/CustomTypeUnboundVariableTest.elm

The `Box` type uses an unbound type variable `a` in its definition:

18| type Box
19|     = Box a
              ^
You probably need to change the declaration to something like this:

    type Box a = ...

Why? Well, imagine one `Box` where `a` is an Int and another where it is a Bool.
When we explicitly list the type variables, the type checker can see that they
are actually different types.

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- UNBOUND TYPE VARIABLE ----------------- src/CustomTypeUnboundVariableTest.elm

The `Box` type uses an unbound type variable `a` in its definition:

18| type Box
19|     = Box a
              ^
You probably need to change the declaration to something like this:

    type Box a = ...

Why? Well, imagine one `Box` where `a` is an Int and another where it is a Bool.
When we explicitly list the type variables, the type checker can see that they
are actually different types.

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- UNBOUND TYPE VARIABLE ----------------- src/CustomTypeUnboundVariableTest.elm

The `Box` type uses an unbound type variable `a` in its definition:

18| type Box
19|     = Box a
              ^
You probably need to change the declaration to something like this:

    type Box a = ...

Why? Well, imagine one `Box` where `a` is an Int and another where it is a Bool.
When we explicitly list the type variables, the type checker can see that they
are actually different types.

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- UNBOUND TYPE VARIABLE ----------------- src/CustomTypeUnboundVariableTest.elm

The `Box` type uses an unbound type variable `a` in its definition:

18| type Box
19|     = Box a
              ^
You probably need to change the declaration to something like this:

    type Box a = ...

Why? Well, imagine one `Box` where `a` is an Int and another where it is a Bool.
When we explicitly list the type variables, the type checker can see that they
are actually different types.

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm/CustomTypeUnboundVariableTest] in its title.

Source

The -- CHECK: lines give the expected output.

module CustomTypeUnboundVariableTest exposing (main)
{-| A custom type's constructors use only the type's parameters.
A Standard Definition of Elm?, restriction modules-custom-type-tyvars: every type variable occurring
in the constructors of a custom type is one of its parameters. `a` is not.
<https://elm-test-suite.netlify.app/standard/restrictions/modules-custom-type-tyvars>
-}
-- TAGS: elm-spec, modules-custom-type-tyvars
-- COMPILE-ERROR: a custom type whose constructor uses an unbound type variable
-- CHECK: {{-- [A-Z ]+ -}}
import Html
type Box
= Box a
main =
Html.text "done"

Lean translation

No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Lean has the program as written, in source syntax, and proves what the static semantics says of it (below). See the Lean mechanisation for which tests are in Lean, and why.

Static semantics: Lean proves that the program as written is not legal, so a compiler must reject it (refuse_elm_CustomTypeUnboundVariableTest, in StandardElmMech/Certs/). The program breaks a syntactic restriction, which the kernel checks on its syntax tree; no type inference is involved (Stat.not_legal_of_syn): res:modules-custom-type-tyvars. It holds for every derivation, with no hypothesis about principality.