Elm Exactly
Results / elm /

PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule s-valbind-varrule s-atexp-longvarrule s-dec-grouprule s-atexp-nil

Translated into Lean for the mechanisation of the book: see its Lean translation.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Tests a polymorphic fold-like function called eight times in a chain, each
with a step function over `( List String, Global )` elements and the previous
call's result as the initial value.

`myFoldl` ignores its function and list and returns its initial value, so
every call returns 0.

Results

elm-0.19.1

passran in 54 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
testValue: 0

elm-0.19.2

passran in 55 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
testValue: 0

elm-0.19.3

passran in 49 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
testValue: 0

lamdera-1.5.0

passran in 60 ms
Output
testValue: 0

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest exposing (..)
{-| Tests a polymorphic fold-like function called eight times in a chain, each
with a step function over `( List String, Global )` elements and the previous
call's result as the initial value.
`myFoldl` ignores its function and list and returns its initial value, so
every call returns 0.
-}
-- TAGS: elm-spec, s-valbind-var, s-atexp-longvar, s-dec-group, s-atexp-nil
-- CHECK: testValue: 0
import Basics exposing (..)
import Char exposing (..)
import List exposing (..)
import Maybe exposing (..)
import String exposing (..)
import Html
type Global
= Global
myFoldl : (a -> b -> b) -> b -> List a -> b
myFoldl f init xs =
init
step : ( List String, Global ) -> Int -> Int
step entry acc =
acc
testValue : Int
testValue =
let
entries =
[]
r1 =
myFoldl step 0 entries
r2 =
myFoldl step r1 entries
r3 =
myFoldl step r2 entries
r4 =
myFoldl step r3 entries
r5 =
myFoldl step r4 entries
r6 =
myFoldl step r5 entries
r7 =
myFoldl step r6 entries
r8 =
myFoldl step r7 entries
in
r8
main =
let
_ =
Debug.log "testValue" testValue
in
Html.text "done"

Lean translation

This program is translated into Lean by the translator of the Lean mechanisation of A Standard Definition of Elm?: the program it is, its modules in the reduced syntax of Chapter 7 with every integer constant at Int or Float by number specialisation, and its CHECK lines as written (g_elm_PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest, in StandardElmMech/Generated/Elm_PartialAppCh.lean). Lean's evaluator runs the program by the rules of Chapters 7 and 9, and its checks become one generated theorem: some derivation of the program has a log that meets every check, or, for a test that stops at Debug.todo, the program has no meaning.

CheckExpected (CHECK)Lean evaluatorProved by
testValue00t_elm_PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest
/-- tests/elm/src/PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest.elm -/
def g_elm_PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest : Program := {
  name := "PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest", source := "tests/elm/src",
  exposing := .all, imports := [⟨"Basics", "Basics", some .all⟩, ⟨"Char", "Char", some .all⟩, ⟨"List", "List", some .all⟩, ⟨"Maybe", "Maybe", some .all⟩, ⟨"String", "String", some .all⟩, ⟨"Html", "Html", none⟩],
  types := [("Global", [("Global", 0)])],
  aliases := [],
  defs := [
    .fn "myFoldl" [pv "f", pv "init", pv "xs"] (v "init"),
    .fn "step" [pv "entry", pv "acc"] (v "acc"),
    .fn "testValue" [] (letDefs [.fn "entries" [] (listE []), .fn "r1" [] (ap (v "myFoldl") [v "step", i 0, v "entries"]), .fn "r2" [] (ap (v "myFoldl") [v "step", v "r1", v "entries"]), .fn "r3" [] (ap (v "myFoldl") [v "step", v "r2", v "entries"]), .fn "r4" [] (ap (v "myFoldl") [v "step", v "r3", v "entries"]), .fn "r5" [] (ap (v "myFoldl") [v "step", v "r4", v "entries"]), .fn "r6" [] (ap (v "myFoldl") [v "step", v "r5", v "entries"]), .fn "r7" [] (ap (v "myFoldl") [v "step", v "r6", v "entries"]), .fn "r8" [] (ap (v "myFoldl") [v "step", v "r7", v "entries"])] (v "r8")),
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "testValue", v "testValue"])] (ap (qv "Html" "text") [str "done"])) ],
  checks := [
    chk .check "testValue: 0" .int ] }

Reading the translation: v "x" is the variable x, c "K" the constructor K, i 42 the integer 42 at Int, .scon (.intF 2) the integer 2 at Float, and str "s" a string; ap f [a, b] applies f to a and then b, and bin "+" a b is a + b. lams, caseOf, ifte, listE, tup2 and recE build lambdas, case, if, lists, pairs and records by the book's derived forms; pv, pw and pcon are variable, wildcard and constructor patterns. defs are the program's top-level definitions and locals the other declarations of main's let, placed in a let around each check; ckk label value kind exp is one check. A name with $ (incF$Float) is a copy number specialisation made.

Static semantics (Chapters 4, 5 and 9): legal_elm_PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest states that the program as written is legal, with no hypothesis: the proved inference W gives each module a principal derivation, which meets the syntactic restrictions and the further restrictions, with a type of main Chapter 9 allows. End to end: spec_elm_PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest states that Lean computes the reduced program above from the source (derived forms, inference, the proved checker, number specialisation, type erasure), so the theorems about it do not trust the translator's elaboration ([elab]); mean_elm_PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_PolyChainFoldlLikeCalled8TimesOverTupleKeyedStructureTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.