LetCycleThroughRecordLambdaTest
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.
A `let` definition without parameters that lies on a cycle is rejected, even when the cycle
goes through a lambda: here a record whose field is a lambda that refers back to the record.
`func = { f = \n -> ... func.f ... }` refers to itself, and is not a function binding with
parameters.
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
passOutput
Compiling ...-- CYCLIC VALUE ------------------------ src/LetCycleThroughRecordLambdaTest.elm
The `func` value is defined directly in terms of itself, causing an infinite
loop.
29| func =
^^^^
Are you are trying to mutate a variable? Elm does not have mutation, so when I
see func defined in terms of func, I treat it as a recursive definition. Try
giving the new value a new name!
Maybe you DO want a recursive value? To define func we need to know what func
is, so let’s expand it. Wait, but now we need to know what func 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
passOutput
Compiling ...-- CYCLIC VALUE ------------------------ src/LetCycleThroughRecordLambdaTest.elm
The `func` value is defined directly in terms of itself, causing an infinite
loop.
29| func =
^^^^
Are you trying to mutate a variable? Elm does not have mutation, so when I see
func defined in terms of func, I treat it as a recursive definition. Try giving
the new value a new name!
Maybe you DO want a recursive value? To define func we need to know what func
is, so let’s expand it. Wait, but now we need to know what func 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
failcompiler killed by SIGSEGV Dependencies ready! Compiling ...-- CYCLIC VALUE ------------------------ src/LetCycleThroughRecordLambdaTest.elm
lamdera-1.5.0
passOutput
Detected problems in 1 module.
-- CYCLIC VALUE ------------------------ src/LetCycleThroughRecordLambdaTest.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/LetCycleThroughRecordLambdaTest] in its title.
Source
The -- CHECK: lines give the expected output.
module LetCycleThroughRecordLambdaTest exposing (main)
{-| A `let` definition without parameters that lies on a cycle is rejected, even when the cycle
goes through a lambda: here a record whose field is a lambda that refers back to the record.
`func = { f = \n -> ... func.f ... }` refers to itself, and is not a function binding with
parameters.
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
-- CHECK: {{-- [A-Z ]+ -}}
import Html
factorial : Int -> Int
factorial num =
let
eval f x =
f () x
func =
{ f =
\n ->
if n == 0 then
1
else
n * eval (\_ -> func.f) (n - 1)
}
in
func.f num
main =
let
_ =
Debug.log "factorial" (factorial 5)
in
Html.text "done"
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_LetCycleThroughRecordLambdaTest, 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.