Elm Exactly
Results / elm /

LetCycleThroughLambdaArgumentTest

Tags:elm-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 fail
A `let` definition without parameters that lies on a cycle is rejected, even when the cycle
goes through a lambda: here a lambda passed as an argument to `Result.andThen`.

`broken = Err () |> Result.andThen (\_ -> ... broken ...)` refers to itself, and is not a function
binding with parameters. The lambda is never called, since `Result.andThen` does not call it on an
`Err`, but the program is rejected all the same.

A Standard Definition of Elm?, restriction core-let-recursion: every definition of a `let` that
lies on a cycle of the refers-to relation is a function binding with at least one parameter; no
definition `var = exp` without parameters lies on a cycle, even when `exp` is a lambda
expression. <https://elm-test-suite.netlify.app/standard/restrictions/core-let-recursion>

Results

elm-0.19.1

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

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

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

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

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

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

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

lamdera-1.5.0

fail
Unexpected pattern (CHECK-NOT): Crash
--- compiler output ---
Detected problems in 1 module.
-- CYCLIC VALUE ---------------------- src/LetCycleThroughLambdaArgumentTest.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/LetCycleThroughLambdaArgumentTest] in its title.

Source

The -- CHECK: lines give the expected output.

module LetCycleThroughLambdaArgumentTest exposing (main)
{-| A `let` definition without parameters that lies on a cycle is rejected, even when the cycle
goes through a lambda: here a lambda passed as an argument to `Result.andThen`.
`broken = Err () |> Result.andThen (\_ -> ... broken ...)` refers to itself, and is not a function
binding with parameters. The lambda is never called, since `Result.andThen` does not call it on an
`Err`, but the program is rejected all the same.
A Standard Definition of Elm?, restriction core-let-recursion: every definition of a `let` that
lies on a cycle of the refers-to relation is a function binding with at least one parameter; no
definition `var = exp` without parameters lies on a cycle, even when `exp` is a lambda
expression. <https://elm-test-suite.netlify.app/standard/restrictions/core-let-recursion>
-}
-- TAGS: elm-spec, core-let-recursion
-- COMPILE-ERROR: a let value on a cycle through a lambda argument
-- CHECK: {{-- [A-Z ]+ -}}
-- CHECK-NOT: Crash
import Html
main =
let
broken : Result () ()
broken =
Err ()
|> Result.andThen
(\_ ->
if False then
broken
else
Ok ()
)
in
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_LetCycleThroughLambdaArgumentTest, 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_syn): res:core-let-recursion. It holds for every derivation, with no hypothesis about principality.