WideRecordDecoder26Test
Tags:elm-spec
Checks, in A Standard Definition of Elm?:rule sm-typbind-recordrule dm-typbindrule d-app-basic-partialrule d-app-basic-apply
Translated into Lean for the mechanisation of the book: see its Lean translation.
A 26-field record alias, used as a constructor function, can be filled in one argument at a time by an `andMap` pipeline over `Maybe`. `andMap` is defined here and applies a `Just` function to a `Just` argument. `build` starts from `Just R` and supplies the 26 `Int` fields, 1000 to 1025, so fields 0, 24 and 25 read back as `Just 1000`, `Just 1024` and `Just 1025`. The local `mapMaybe` reads each field inside the `Maybe`.
Results
elm-0.19.1
passran in 66 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. f0000: Just 1000 f0024: Just 1024 f0025: Just 1025
elm-0.19.2
passran in 61 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. f0000: Just 1000 f0024: Just 1024 f0025: Just 1025
elm-0.19.3
passran in 72 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. f0025: Just 1025 f0024: Just 1024 f0000: Just 1000
lamdera-1.5.0
passran in 42 msOutput
f0025: Just 1025 f0024: Just 1024 f0000: Just 1000
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/WideRecordDecoder26Test] in its title.
Source
The -- CHECK: lines give the expected output.
module WideRecordDecoder26Test exposing (main)
{-| A 26-field record alias, used as a constructor function, can be filled in one
argument at a time by an `andMap` pipeline over `Maybe`.
`andMap` is defined here and applies a `Just` function to a `Just` argument.
`build` starts from `Just R` and supplies the 26 `Int` fields, 1000 to 1025, so
fields 0, 24 and 25 read back as `Just 1000`, `Just 1024` and `Just 1025`.
The local `mapMaybe` reads each field inside the `Maybe`.
-}
-- TAGS: elm-spec, sm-typbind-record, dm-typbind, d-app-basic-partial, d-app-basic-apply
-- CHECK: f0000: Just 1000
-- CHECK: f0024: Just 1024
-- CHECK: f0025: Just 1025
import Html exposing (text)
type alias R =
{ f0000 : Int
, f0001 : Int
, f0002 : Int
, f0003 : Int
, f0004 : Int
, f0005 : Int
, f0006 : Int
, f0007 : Int
, f0008 : Int
, f0009 : Int
, f0010 : Int
, f0011 : Int
, f0012 : Int
, f0013 : Int
, f0014 : Int
, f0015 : Int
, f0016 : Int
, f0017 : Int
, f0018 : Int
, f0019 : Int
, f0020 : Int
, f0021 : Int
, f0022 : Int
, f0023 : Int
, f0024 : Int
, f0025 : Int
}
andMap : Maybe a -> Maybe (a -> b) -> Maybe b
andMap ma mf =
case ( mf, ma ) of
( Just f, Just a ) ->
Just (f a)
_ ->
Nothing
mapMaybe : (a -> b) -> Maybe a -> Maybe b
mapMaybe f ma =
case ma of
Just a ->
Just (f a)
Nothing ->
Nothing
build : Int -> Maybe R
build b =
Just R
|> andMap (Just (b + 999))
|> andMap (Just (b + 1000))
|> andMap (Just (b + 1001))
|> andMap (Just (b + 1002))
|> andMap (Just (b + 1003))
|> andMap (Just (b + 1004))
|> andMap (Just (b + 1005))
|> andMap (Just (b + 1006))
|> andMap (Just (b + 1007))
|> andMap (Just (b + 1008))
|> andMap (Just (b + 1009))
|> andMap (Just (b + 1010))
|> andMap (Just (b + 1011))
|> andMap (Just (b + 1012))
|> andMap (Just (b + 1013))
|> andMap (Just (b + 1014))
|> andMap (Just (b + 1015))
|> andMap (Just (b + 1016))
|> andMap (Just (b + 1017))
|> andMap (Just (b + 1018))
|> andMap (Just (b + 1019))
|> andMap (Just (b + 1020))
|> andMap (Just (b + 1021))
|> andMap (Just (b + 1022))
|> andMap (Just (b + 1023))
|> andMap (Just (b + 1024))
main =
let
base =
1 + (Char.toCode 'b' - Char.toCode 'a') - 1
r =
build base
_ =
Debug.log "f0000" (mapMaybe .f0000 r)
_ =
Debug.log "f0024" (mapMaybe .f0024 r)
_ =
Debug.log "f0025" (mapMaybe .f0025 r)
in
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_WideRecordDecoder26Test, in StandardElmMech/Generated/Elm_TailRecT.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.
| Check | Expected (CHECK) | Lean evaluator | Proved by |
|---|---|---|---|
f0000 | Just 1000 | Just 1000 | t_elm_WideRecordDecoder26Test |
f0024 | Just 1024 | Just 1024 | t_elm_WideRecordDecoder26Test |
f0025 | Just 1025 | Just 1025 | t_elm_WideRecordDecoder26Test |
/-- tests/elm/src/WideRecordDecoder26Test.elm -/
def g_elm_WideRecordDecoder26Test : Program := {
name := "WideRecordDecoder26Test", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [],
aliases := [("R", some ["f0000", "f0001", "f0002", "f0003", "f0004", "f0005", "f0006", "f0007", "f0008", "f0009", "f0010", "f0011", "f0012", "f0013", "f0014", "f0015", "f0016", "f0017", "f0018", "f0019", "f0020", "f0021", "f0022", "f0023", "f0024", "f0025"])],
defs := [
.fn "andMap" [pv "ma", pv "mf"] (caseOf (tup2 (v "mf") (v "ma")) [(P (ptup2 (pcon "Just" [pv "f"]) (pcon "Just" [pv "a"])), ap (c "Just") [.atexp (.paren (ap (v "f") [v "a"]))]), (P pw, c "Nothing")]),
.fn "mapMaybe" [pv "f", pv "ma"] (caseOf (v "ma") [(pcon "Just" [pv "a"], ap (c "Just") [.atexp (.paren (ap (v "f") [v "a"]))]), (P (pcA "Nothing"), c "Nothing")]),
.fn "build" [pv "b"] (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (bin "|>" (ap (c "Just") [c "R"]) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 999)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1000)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1001)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1002)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1003)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1004)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1005)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1006)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1007)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1008)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1009)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1010)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1011)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1012)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1013)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1014)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1015)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1016)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1017)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1018)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1019)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1020)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1021)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1022)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1023)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1024)))]))])),
.fn "main" [] (letDefs [.fn "base" [] (bin "-" (bin "+" (i 1) (.atexp (.paren (bin "-" (ap (qv "Char" "toCode") [.atexp (chA 'b')]) (ap (qv "Char" "toCode") [.atexp (chA 'a')]))))) (i 1)), .fn "r" [] (ap (v "build") [v "base"]), .pat pw (ap (qv "Debug" "log") [str "f0000", .atexp (.paren (ap (v "mapMaybe") [.atexp (accessor "f0000"), v "r"]))]), .pat pw (ap (qv "Debug" "log") [str "f0024", .atexp (.paren (ap (v "mapMaybe") [.atexp (accessor "f0024"), v "r"]))]), .pat pw (ap (qv "Debug" "log") [str "f0025", .atexp (.paren (ap (v "mapMaybe") [.atexp (accessor "f0025"), v "r"]))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "f0000: Just 1000" .data,
chk .check "f0024: Just 1024" .data,
chk .check "f0025: Just 1025" .data ] }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_WideRecordDecoder26Test 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_WideRecordDecoder26Test 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_WideRecordDecoder26Test states that the program has a meaning by r:p-program, with both premises, and ident_elm_WideRecordDecoder26Test that its specialisation is unique and is the reduced program above, both with no hypothesis about principality. One of these theorems is proved by native_decide ([native]).