Elm Exactly
Results / elm /

WideRecordDecoder30Test

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.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
A 30-field record alias, used as a constructor function, can be filled in one
argument at a time by an `andMap` pipeline over `Maybe`, with fields of
different types near the end.

`andMap` is defined here and applies a `Just` function to a `Just` argument.
Fields 0 to 24 are `Int`s; fields 25 to 29 are a `Float`, a `Char`, an `Int`, a
`String` and an `Int`. The test reads back field 0 and fields 24 to 29.
The local `mapMaybe` reads each field inside the `Maybe`.

Results

elm-0.19.1

passran in 57 ms
Output
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 25.5
f0026: Just 'a'
f0027: Just 1027
f0028: Just "28s"
f0029: Just 1029

elm-0.19.2

passran in 57 ms
Output
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 25.5
f0026: Just 'a'
f0027: Just 1027
f0028: Just "28s"
f0029: Just 1029

elm-0.19.3

passran in 74 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
f0029: Just 1029
f0028: Just "28s"
f0027: Just 1027
f0026: Just 'a'
f0025: Just 25.5
f0024: Just 1024
f0000: Just 1000

lamdera-1.5.0

passran in 70 ms
Output
f0029: Just 1029
f0028: Just "28s"
f0027: Just 1027
f0026: Just 'a'
f0025: Just 25.5
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/WideRecordDecoder30Test] in its title.

Source

The -- CHECK: lines give the expected output.

module WideRecordDecoder30Test exposing (main)
{-| A 30-field record alias, used as a constructor function, can be filled in one
argument at a time by an `andMap` pipeline over `Maybe`, with fields of
different types near the end.
`andMap` is defined here and applies a `Just` function to a `Just` argument.
Fields 0 to 24 are `Int`s; fields 25 to 29 are a `Float`, a `Char`, an `Int`, a
`String` and an `Int`. The test reads back field 0 and fields 24 to 29.
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 25.5
-- CHECK: f0026: Just 'a'
-- CHECK: f0027: Just 1027
-- CHECK: f0028: Just "28s"
-- CHECK: f0029: Just 1029
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 : Float
, f0026 : Char
, f0027 : Int
, f0028 : String
, f0029 : 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 (toFloat b + 25.5 - 1))
|> andMap (Just ((if b == 1 then 'a' else '?')))
|> andMap (Just (b + 1026))
|> andMap (Just ((if b == 1 then "28s" else "?")))
|> andMap (Just (b + 1028))
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)
_ =
Debug.log "f0026" (mapMaybe .f0026 r)
_ =
Debug.log "f0027" (mapMaybe .f0027 r)
_ =
Debug.log "f0028" (mapMaybe .f0028 r)
_ =
Debug.log "f0029" (mapMaybe .f0029 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_WideRecordDecoder30Test, 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.

CheckExpected (CHECK)Lean evaluatorProved by
f0000Just 1000Just 1000t_elm_WideRecordDecoder30Test
f0024Just 1024Just 1024t_elm_WideRecordDecoder30Test
f0025Just 25.5Just 25.5t_elm_WideRecordDecoder30Test
f0026Just 'a'Just 'a't_elm_WideRecordDecoder30Test
f0027Just 1027Just 1027t_elm_WideRecordDecoder30Test
f0028Just "28s"Just "28s"t_elm_WideRecordDecoder30Test
f0029Just 1029Just 1029t_elm_WideRecordDecoder30Test
/-- tests/elm/src/WideRecordDecoder30Test.elm -/
def g_elm_WideRecordDecoder30Test : Program := {
  name := "WideRecordDecoder30Test", 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", "f0026", "f0027", "f0028", "f0029"])],
  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 "|>" (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 "-" (bin "+" (ap (v "toFloat") [v "b"]) (.atexp (.scon (.float 255 (-1))))) (.atexp (.scon (.intF 1)))))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (.atexp (.paren (ifte (bin "==" (v "b") (i 1)) (.atexp (chA 'a')) (.atexp (chA '?'))))))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1026)))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (.atexp (.paren (ifte (bin "==" (v "b") (i 1)) (str "28s") (str "?")))))]))])) (ap (v "andMap") [.atexp (.paren (ap (c "Just") [.atexp (.paren (bin "+" (v "b") (i 1028)))]))])),
    .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"]))]), .pat pw (ap (qv "Debug" "log") [str "f0026", .atexp (.paren (ap (v "mapMaybe") [.atexp (accessor "f0026"), v "r"]))]), .pat pw (ap (qv "Debug" "log") [str "f0027", .atexp (.paren (ap (v "mapMaybe") [.atexp (accessor "f0027"), v "r"]))]), .pat pw (ap (qv "Debug" "log") [str "f0028", .atexp (.paren (ap (v "mapMaybe") [.atexp (accessor "f0028"), v "r"]))]), .pat pw (ap (qv "Debug" "log") [str "f0029", .atexp (.paren (ap (v "mapMaybe") [.atexp (accessor "f0029"), v "r"]))])] (ap (v "text") [str "done"])) ],
  checks := [
    chk .check "f0000: Just 1000" .data,
    chk .check "f0024: Just 1024" .data,
    chk .check "f0025: Just 25.5" .data,
    chk .check "f0026: Just 'a'" .data,
    chk .check "f0027: Just 1027" .data,
    chk .check "f0028: Just \"28s\"" .data,
    chk .check "f0029: Just 1029" .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_WideRecordDecoder30Test 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_WideRecordDecoder30Test 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_WideRecordDecoder30Test states that the program has a meaning by r:p-program, with both premises, and ident_elm_WideRecordDecoder30Test 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]).