Elm Exactly
Results / elm /

CyclicDefinitionATopLevelValueDefinedByItselfTest

Tags:elm19-compile-errorelm-spec

Checks, in A Standard Definition of Elm?:restriction modules-value-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 fail
A top-level value defined in terms of itself is rejected with a CYCLIC DEFINITION error.

`loop` is defined as `loop + 1`. It takes no arguments, so evaluating it would never finish.

Results

elm-0.19.1

pass
Output
Compiling ...-- CYCLIC DEFINITION - src/CyclicDefinitionATopLevelValueDefinedByItselfTest.elm

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

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

Maybe you DO want a recursive value? To define loop we need to know what loop
is, so let’s expand it. Wait, but now we need to know what loop 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 DEFINITION - src/CyclicDefinitionATopLevelValueDefinedByItselfTest.elm

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

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

Maybe you DO want a recursive value? To define loop we need to know what loop
is, so let’s expand it. Wait, but now we need to know what loop 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 ...

lamdera-1.5.0

fail
Missing pattern: -- CYCLIC DEFINITION -
--- compiler output ---

-- ERROR -----------------------------------------------------------------------

lamdera-1.5.0-0.19.3-linux-x86_64-1ec0a3a092ea4c714f98404cd529abe37b0673e0 (Mon
Oct 26 11:38:05 2026 +1100) (branch:distribute)

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   Crash {_module = Module "Graph", _name = Name "Graph.withMinimalCycle", _line = Line 273, _message = "bug in RootSelector when calculating minimal cycle"} (in module CyclicDefinitionATopLevelValueDefinedByItselfTest)

These errors are usually pretty confusing, so start by asking around on Discord
https://dashboard.lamdera.app/docs/discuss to see if anyone can get you unstuck
quickly.

-- REQUEST ---------------------------------------------------------------------

If you are feeling up to it, please try to get your code down to the smallest
version that still triggers this message. Ideally in a single Main.elm and
elm.json file.

From there open a NEW issue at https://github.com/elm/compiler/issues with your
reduced example pasted in directly. (Not a link to a repo or gist!) Do not worry
about if someone else saw something similar. More examples is better!

This kind of error is usually tied up in larger architectural choices that are
hard to change, so even when we have a couple good examples, it can take some
time to resolve in a solid way.lamdera: Crash {_module = Module "Graph", _name = Name "Graph.withMinimalCycle", _line = Line 273, _message = "bug in RootSelector when calculating minimal cycle"} (in module CyclicDefinitionATopLevelValueDefinedByItselfTest)

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module CyclicDefinitionATopLevelValueDefinedByItselfTest exposing (..)
{-| A top-level value defined in terms of itself is rejected with a CYCLIC DEFINITION error.
`loop` is defined as `loop + 1`. It takes no arguments, so evaluating it would never finish.
-}
-- TAGS: elm19-compile-error
-- TAGS: elm-spec, modules-value-recursion
-- COMPILE-ERROR: CYCLIC DEFINITION, a top-level value defined by itself
-- CHECK: -- CYCLIC DEFINITION -
loop =
loop + 1
testValue =
loop

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_CyclicDefinitionATopLevelValueDefinedByItselfTest, 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:modules-value-recursion. It holds for every derivation, with no hypothesis about principality.