CompilerIssue2241FoldMapInfiniteTypeHangTest
Checks, in A Standard Definition of Elm?:rule s-exp-app
Not translated into Lean for the mechanisation of the book: see why.
Issue: elm/compiler#2241
The compiler rejects, with a type error, a call whose tuple-accumulating lambda does not fit the function it is passed to. <https://github.com/elm/compiler/issues/2241> In `break`, `foldMap` requires its third argument to have type `Float -> ( Float, Float ) -> ( Float, Float )`, but the lambda given takes a tuple first and returns a tuple mixing its components with its second argument, which leads the type checker to an infinite type. Elm 0.19.1 does not report this: it hangs with memory growing without bound, or crashes.
Results
elm-0.19.1
failcompiler used more than 4096 MB of memory Dependencies ready! Compiling ...
elm-0.19.2
failcompiler used more than 4096 MB of memory Dependencies ready! Compiling ...
elm-0.19.3
failcompiler used more than 4096 MB of memory Dependencies ready! Compiling ...
lamdera-1.5.0
failcompiler used more than 4096 MB of memory Verifying dependencies (10/10)
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/CompilerIssue2241FoldMapInfiniteTypeHangTest] in its title.
Source
The -- CHECK: lines give the expected output.
module CompilerIssue2241FoldMapInfiniteTypeHangTest exposing (main)
{-| The compiler rejects, with a type error, a call whose tuple-accumulating lambda does not fit the function it is passed to.
<https://github.com/elm/compiler/issues/2241>
In `break`, `foldMap` requires its third argument to have type `Float -> ( Float, Float ) -> ( Float, Float )`,
but the lambda given takes a tuple first and returns a tuple mixing its components with its second argument,
which leads the type checker to an infinite type. Elm 0.19.1 does not report this: it hangs
with memory growing without bound, or crashes.
-}
-- TAGS: elm19-bug
-- TAGS: elm-spec, s-exp-app
-- COMPILE-ERROR: a type error, not a hang
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: HasCallStack
import Html
foldMap : (a -> b) -> (a -> c) -> (b -> c -> c) -> a -> c
foldMap fab fac fbc a = fac a
break : Float -> (Float, Float)
break input = foldMap identity (\x -> (x, x)) (\( low, high ) x -> ( min low x, max high x )) input
main =
Html.text ""
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_CompilerIssue2241FoldMapInfiniteTypeHangTest, in StandardElmMech/Certs/). The kernel finds a core of the program's typing constraints that has no solution, so no derivation types it (core refutation, plan step 11) (Stat.not_legal_of_coreRefutes). It holds for every derivation, with no hypothesis about principality.