CompilerIssue1858AnnotatedPolymorphicRecursionTest
Checks, in A Standard Definition of Elm?:rule sm-topdec-valuerule s-valbind-var
Translated into Lean for the mechanisation of the book: see its Lean translation.
Issue: elm/compiler#1858
A recursive call at a different type argument is rejected despite the annotation. <https://github.com/elm/compiler/issues/1858> `bVals : Silly a b -> Maybe b` is annotated, so the recursive call `bVals nested` at `Silly Int b` is well-typed (polymorphic recursion, allowed because of the annotation). Elm 0.19.1 reports a type mismatch saying it needs `Silly a b`.
Results
elm-0.19.1
failcompile failed (exit 1):
Compiling ...-- TYPE MISMATCH ---- src/CompilerIssue1858AnnotatedPolymorphicRecursionTest.elm
The 1st argument to `bVals` is not what I expect:
33| bVals nested
^^^^^^
This `nested` value is a:
Silly Int b
But `bVals` needs the 1st argument to be:
Silly a b
Hint: Your type annotation uses type variable `a` which means ANY type of value
can flow through, but your code is saying it specifically wants a `Int` value.
Maybe change your type annotation to be more specific? Maybe change the code to
be more general?
Read <https://elm-lang.org/0.19.1/type-annotations> for more advice!
Detected problems in 1 module.
elm-0.19.2
failcompile failed (exit 1):
Compiling ...-- TYPE MISMATCH ---- src/CompilerIssue1858AnnotatedPolymorphicRecursionTest.elm
The 1st argument to `bVals` is not what I expect:
33| bVals nested
^^^^^^
This `nested` value is a:
Silly Int b
But `bVals` needs the 1st argument to be:
Silly a b
Hint: Your type annotation uses type variable `a` which means ANY type of value
can flow through, but your code is saying it specifically wants a `Int` value.
Maybe change your type annotation to be more specific? Maybe change the code to
be more general?
Read <https://elm-lang.org/0.19.2/type-annotations> for more advice!
Detected problems in 1 module.
elm-0.19.3
failcompile failed (exit 1):
Dependencies ready!
Compiling ...-- TYPE MISMATCH ---- src/CompilerIssue1858AnnotatedPolymorphicRecursionTest.elm
The 1st argument to `bVals` is not what I expect:
33| bVals nested
^^^^^^
This `nested` value is a:
Silly Int b
But `bVals` needs the 1st argument to be:
Silly a b
Hint: Your type annotation uses type variable `a` which means ANY type of value
can flow through, but your code is saying it specifically wants a `Int` value.
Maybe change your type annotation to be more specific? Maybe change the code to
be more general?
Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!
Detected problems in 1 module.
lamdera-1.5.0
failcompile failed (exit 1):
Dependencies ready!
Detected problems in 1 module.
-- TYPE MISMATCH ---- src/CompilerIssue1858AnnotatedPolymorphicRecursionTest.elm
The 1st argument to `bVals` is not what I expect:
33| bVals nested
^^^^^^
This `nested` value is a:
Silly Int b
But `bVals` needs the 1st argument to be:
Silly a b
Hint: Your type annotation uses type variable `a` which means ANY type of value
can flow through, but your code is saying it specifically wants a `Int` value.
Maybe change your type annotation to be more specific? Maybe change the code to
be more general?
Read <https://elm-lang.org/0.19.3/type-annotations> for more advice!
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/CompilerIssue1858AnnotatedPolymorphicRecursionTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CompilerIssue1858AnnotatedPolymorphicRecursionTest exposing (..)
{-| A recursive call at a different type argument is rejected despite the annotation.
<https://github.com/elm/compiler/issues/1858>
`bVals : Silly a b -> Maybe b` is annotated, so the recursive call `bVals nested` at
`Silly Int b` is well-typed (polymorphic recursion, allowed because of the annotation).
Elm 0.19.1 reports a type mismatch saying it needs `Silly a b`.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, sm-topdec-value, s-valbind-var
-- CHECK: bVals: Just "b"
import Html exposing (text)
type Silly a b
= AsB b
| DeeplySilly (Silly a a) (Silly Int b)
| NoArg
bVals : Silly a b -> Maybe b
bVals silly =
case silly of
AsB b ->
Just b
DeeplySilly _ nested ->
bVals nested
NoArg ->
Nothing
value : Silly () String
value =
DeeplySilly NoArg (AsB "b")
main =
let
_ =
Debug.log "bVals" (bVals value)
in
text "done"
Lean translation
This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_CompilerIssue1858AnnotatedPolymorphicRecursionTest, in StandardElmMech/Generated/Elm_CombinatorSP.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
bVals | Just "b" | Just "b" | t_elm_CompilerIssue1858AnnotatedPolymorphicRecursionTest |
/-- tests/elm/src/CompilerIssue1858AnnotatedPolymorphicRecursionTest.elm -/
def g_elm_CompilerIssue1858AnnotatedPolymorphicRecursionTest : Program := {
name := "CompilerIssue1858AnnotatedPolymorphicRecursionTest", source := "tests/elm/src",
exposing := .all, imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [("Silly", [("AsB", 1), ("DeeplySilly", 2), ("NoArg", 0)])],
aliases := [],
defs := [
.fn "bVals" [pv "silly"] (caseOf (v "silly") [(pcon "AsB" [pv "b"], ap (c "Just") [v "b"]), (pcon "DeeplySilly" [pw, pv "nested"], ap (v "bVals") [v "nested"]), (P (pcA "NoArg"), c "Nothing")]),
.fn "value" [] (ap (c "DeeplySilly") [c "NoArg", .atexp (.paren (ap (c "AsB") [str "b"]))]),
.fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "bVals", .atexp (.paren (ap (v "bVals") [v "value"]))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "bVals: Just \"b\"" .data ] }Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.
Static semantics (Chapters 4, 5 and 9): legal_elm_CompilerIssue1858AnnotatedPolymorphicRecursionTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_CompilerIssue1858AnnotatedPolymorphicRecursionTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_CompilerIssue1858AnnotatedPolymorphicRecursionTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_CompilerIssue1858AnnotatedPolymorphicRecursionTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.