Elm Exactly
Results / elm /

CyclicValueALetValueDefinedByItselfTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:restriction core-let-recursion

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

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 faillamdera-1.5.0 pass
A let-bound value defined in terms of itself is rejected with a CYCLIC VALUE error.

Inside `testValue`, the let binding `y` is defined as `y + 1`. It takes no arguments, so
evaluating it would never finish.

Results

elm-0.19.1

pass
Output
Compiling ...-- CYCLIC VALUE ---------------- src/CyclicValueALetValueDefinedByItselfTest.elm

The `y` value is defined directly in terms of itself, causing an infinite loop.

17|         y =
            ^
Are you are trying to mutate a variable? Elm does not have mutation, so when I
see y defined in terms of y, I treat it as a recursive definition. Try giving
the new value a new name!

Maybe you DO want a recursive value? To define y we need to know what y is, so
let’s expand it. Wait, but now we need to know what y is, so let’s expand it...
This will keep going infinitely!

Hint: The root problem is often a typo in some variable name, but I recommend
reading <https://elm-lang.org/0.19.1/bad-recursion> for more detailed advice,
especially if you actually do need a recursive value.

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- CYCLIC VALUE ---------------- src/CyclicValueALetValueDefinedByItselfTest.elm

The `y` value is defined directly in terms of itself, causing an infinite loop.

17|         y =
            ^
Are you trying to mutate a variable? Elm does not have mutation, so when I see y
defined in terms of y, I treat it as a recursive definition. Try giving the new
value a new name!

Maybe you DO want a recursive value? To define y we need to know what y is, so
let’s expand it. Wait, but now we need to know what y is, so let’s expand it...
This will keep going infinitely!

Hint: The root problem is often a typo in some variable name, but I recommend
reading <https://elm-lang.org/0.19.2/bad-recursion> for more detailed advice,
especially if you actually do need a recursive value.

Detected problems in 1 module.

elm-0.19.3

fail
compiler killed by SIGSEGV
Dependencies ready!
Compiling ...-- CYCLIC VALUE ---------------- src/CyclicValueALetValueDefinedByItselfTest.elm

lamdera-1.5.0

pass
Output
Dependencies ready!
Detected problems in 1 module.
-- CYCLIC VALUE ---------------- src/CyclicValueALetValueDefinedByItselfTest.elm

lamdera: Crash {_module = Module "Graph", _name = Name "Graph.withMinimalCycle", _line = Line 273, _message = "bug in RootSelector when calculating minimal cycle"}

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CyclicValueALetValueDefinedByItselfTest exposing (..)
{-| A let-bound value defined in terms of itself is rejected with a CYCLIC VALUE error.
Inside `testValue`, the let binding `y` is defined as `y + 1`. It takes no arguments, so
evaluating it would never finish.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, core-let-recursion
-- COMPILE-ERROR: CYCLIC VALUE, a let value defined by itself
-- CHECK: -- CYCLIC VALUE -
testValue =
let
y =
y + 1
in
y

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_CyclicValueALetValueDefinedByItselfTest, 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_modsyn): res:core-let-recursion. It holds for every derivation, with no hypothesis about principality.