UnexpectedPatternFloatWithExponentTest
Tags:elm19-compile-errorelm-spec
Checks, in A Standard Definition of Elm?:restriction core-no-float-pattern
Not translated into Lean for the mechanisation of the book: see why.
A case branch whose pattern is the float literal `1e3` is rejected with an UNEXPECTED PATTERN error. Elm patterns may match integer, character and string literals but not floats, and a literal written with an exponent is a float.
Results
elm-0.19.1
passOutput
Compiling ...-- UNEXPECTED PATTERN ----------- src/UnexpectedPatternFloatWithExponentTest.elm
I cannot pattern match with floating point numbers:
19| 1e3 ->
^^^
Equality on floats can be unreliable, so you usually want to check that they are
nearby with some sort of (abs (actual - expected) < 0.001) check.
Detected problems in 1 module.
elm-0.19.2
passOutput
Compiling ...-- UNEXPECTED PATTERN ----------- src/UnexpectedPatternFloatWithExponentTest.elm
I cannot pattern match with floating point numbers:
19| 1e3 ->
^^^
Equality on floats can be unreliable, so you usually want to check that they are
nearby with some sort of (abs (actual - expected) < 0.001) check.
Detected problems in 1 module.
elm-0.19.3
passOutput
Compiling ...-- UNEXPECTED PATTERN ----------- src/UnexpectedPatternFloatWithExponentTest.elm
I cannot pattern match with floating point numbers:
19| 1e3 ->
^^^
Equality on floats can be unreliable, so you usually want to check that they are
nearby with some sort of (abs (actual - expected) < 0.001) check.
Detected problems in 1 module.
lamdera-1.5.0
passOutput
Detected problems in 1 module.
-- UNEXPECTED PATTERN ----------- src/UnexpectedPatternFloatWithExponentTest.elm
I cannot pattern match with floating point numbers:
19| 1e3 ->
^^^
Equality on floats can be unreliable, so you usually want to check that they are
nearby with some sort of (abs (actual - expected) < 0.001) check.
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/UnexpectedPatternFloatWithExponentTest] in its title.
Source
The -- CHECK: lines give the expected output.
module UnexpectedPatternFloatWithExponentTest exposing (main)
{-| A case branch whose pattern is the float literal `1e3` is rejected with an UNEXPECTED
PATTERN error.
Elm patterns may match integer, character and string literals but not floats, and a literal
written with an exponent is a float.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-no-float-pattern
-- COMPILE-ERROR: UNEXPECTED PATTERN
-- CHECK: -- UNEXPECTED PATTERN -
f x =
case x of
1e3 ->
1
_ ->
2
main =
f 2
Lean translation
No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Static semantics: expected to be rejected, and eco's parser rejects it too. See the Lean mechanisation for which tests are in Lean, and why.