AppendTypeSplitTest
Tags:elm-spec
Checks, in A Standard Definition of Elm?:basis Basics.append
Translated into Lean for the mechanisation of the book: see its Lean translation.
`++` gives the right result on `String`s and `List`s, including empty operands, long strings, nested appends, and a function whose type is `appendable`. Each of `String` and `List` is appended with an empty operand on the left, on the right, and on both sides. The string cases also compare two 131,072-character strings built by `++` in different ways: equal when they hold the same characters, and not equal when only the last one differs. The list cases also append a list computed element by element. Slices and the length of a long string, which only library functions can observe, are checked by AppendSliceLengthTest.
Results
elm-0.19.1
passran in 62 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. strs: "foobar" strEmptyR: "foo" strEmptyL: "foo" strBothEmpty: "" ropeEq: True ropeNeq: False lists: [1,2,3,4] listEmptyR: [1,2] listEmptyL: [1,2] listBothEmpty: [] chunkAppend: [2,4,6,1] nested: "abcdef" polyStr: "hihi" polyList: [7,7]
elm-0.19.2
passran in 62 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. strs: "foobar" strEmptyR: "foo" strEmptyL: "foo" strBothEmpty: "" ropeEq: True ropeNeq: False lists: [1,2,3,4] listEmptyR: [1,2] listEmptyL: [1,2] listBothEmpty: [] chunkAppend: [2,4,6,1] nested: "abcdef" polyStr: "hihi" polyList: [7,7]
elm-0.19.3
passran in 66 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. strs: "foobar" strEmptyR: "foo" strEmptyL: "foo" strBothEmpty: "" ropeEq: True ropeNeq: False lists: [1,2,3,4] listEmptyR: [1,2] listEmptyL: [1,2] listBothEmpty: [] chunkAppend: [2,4,6,1] nested: "abcdef" polyStr: "hihi" polyList: [7,7]
lamdera-1.5.0
passran in 53 msOutput
strs: "foobar" strEmptyR: "foo" strEmptyL: "foo" strBothEmpty: "" ropeEq: True ropeNeq: False lists: [1,2,3,4] listEmptyR: [1,2] listEmptyL: [1,2] listBothEmpty: [] chunkAppend: [2,4,6,1] nested: "abcdef" polyStr: "hihi" polyList: [7,7]
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm/AppendTypeSplitTest] in its title.
Source
The -- CHECK: lines give the expected output.
module AppendTypeSplitTest exposing (main)
{-| `++` gives the right result on `String`s and `List`s, including empty operands, long strings, nested appends, and a function whose type is `appendable`.
Each of `String` and `List` is appended with an empty operand on the left, on
the right, and on both sides. The string cases also compare two 131,072-character
strings built by `++` in different ways: equal when they hold the same characters,
and not equal when only the last one differs. The list cases also append a list
computed element by element. Slices and the length of a long string, which only
library functions can observe, are checked by AppendSliceLengthTest.
-}
-- TAGS: elm-spec, b:Basics.append
-- CHECK: strs: "foobar"
-- CHECK: strEmptyR: "foo"
-- CHECK: strEmptyL: "foo"
-- CHECK: strBothEmpty: ""
-- CHECK: ropeEq: True
-- CHECK: ropeNeq: False
-- CHECK: lists: [1,2,3,4]
-- CHECK: listEmptyR: [1,2]
-- CHECK: listEmptyL: [1,2]
-- CHECK: listBothEmpty: []
-- CHECK: chunkAppend: [2,4,6,1]
-- CHECK: nested: "abcdef"
-- CHECK: polyStr: "hihi"
-- CHECK: polyList: [7,7]
import Html exposing (text)
{-| Two string literals appended.
-}
strs : String
strs =
"foo" ++ "bar"
{-| `s` appended to itself `n` times over: 2^n copies of `s`.
-}
doubled : Int -> String -> String
doubled n s =
if n <= 0 then
s
else
doubled (n - 1) (s ++ s)
{-| A 131,072-character string: 65,536 `a`s appended to 65,536 `b`s.
-}
ropeStr : String
ropeStr =
doubled 16 "a" ++ doubled 16 "b"
{-| The same characters as `ropeStr`, appended in another grouping: the `b`s in two halves.
-}
ropeStr2 : String
ropeStr2 =
doubled 16 "a" ++ (doubled 15 "b" ++ doubled 15 "b")
{-| `ropeStr` with its last character changed: the `b`s end in a `c`.
-}
ropeStrLastC : String
ropeStrLastC =
doubled 16 "a" ++ (doubled 15 "b" ++ (doubled 14 "b" ++ (doubled 13 "b" ++ (doubled 12 "b" ++ (doubled 11 "b" ++ (doubled 10 "b" ++ (doubled 9 "b" ++ (doubled 8 "b" ++ (doubled 7 "b" ++ (doubled 6 "b" ++ (doubled 5 "b" ++ (doubled 4 "b" ++ (doubled 3 "b" ++ (doubled 2 "b" ++ (doubled 1 "b" ++ ("b" ++ "c"))))))))))))))))
{-| Two list literals appended.
-}
lists : List Int
lists =
[ 1, 2 ] ++ [ 3, 4 ]
{-| A list computed element by element appended to a list literal.
-}
chunkAppend : List Int
chunkAppend =
[ 1 * 2, 2 * 2, 3 * 2 ] ++ [ 1 ]
{-| Three strings appended, where the left operand is itself an append.
-}
nested : String
nested =
("ab" ++ "cd") ++ "ef"
{-| Returns `x` appended to itself. Its type is `appendable`, and the test uses it
at `String` and at `List`.
-}
twice : appendable -> appendable
twice x =
x ++ x
main : Html.Html msg
main =
let
_ =
Debug.log "strs" strs
_ =
Debug.log "strEmptyR" ("foo" ++ "")
_ =
Debug.log "strEmptyL" ("" ++ "foo")
_ =
Debug.log "strBothEmpty" ("" ++ "")
_ =
Debug.log "ropeEq" (ropeStr == ropeStr2)
_ =
Debug.log "ropeNeq" (ropeStr == ropeStrLastC)
_ =
Debug.log "lists" lists
_ =
Debug.log "listEmptyR" ([ 1, 2 ] ++ [])
_ =
Debug.log "listEmptyL" ([] ++ [ 1, 2 ])
_ =
Debug.log "listBothEmpty" ([] ++ [])
_ =
Debug.log "chunkAppend" chunkAppend
_ =
Debug.log "nested" nested
_ =
Debug.log "polyStr" (twice "hi")
_ =
Debug.log "polyList" (twice [ 7 ])
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_AppendTypeSplitTest, in StandardElmMech/Generated/Elm_Ap.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 |
|---|---|---|---|
strs | "foobar" | "foobar" | t_elm_AppendTypeSplitTest |
strEmptyR | "foo" | "foo" | t_elm_AppendTypeSplitTest |
strEmptyL | "foo" | "foo" | t_elm_AppendTypeSplitTest |
strBothEmpty | "" | "" | t_elm_AppendTypeSplitTest |
ropeEq | True | True | t_elm_AppendTypeSplitTest |
ropeNeq | False | False | t_elm_AppendTypeSplitTest |
lists | [1,2,3,4] | [1,2,3,4] | t_elm_AppendTypeSplitTest |
listEmptyR | [1,2] | [1,2] | t_elm_AppendTypeSplitTest |
listEmptyL | [1,2] | [1,2] | t_elm_AppendTypeSplitTest |
listBothEmpty | [] | [] | t_elm_AppendTypeSplitTest |
chunkAppend | [2,4,6,1] | [2,4,6,1] | t_elm_AppendTypeSplitTest |
nested | "abcdef" | "abcdef" | t_elm_AppendTypeSplitTest |
polyStr | "hihi" | "hihi" | t_elm_AppendTypeSplitTest |
polyList | [7,7] | [7,7] | t_elm_AppendTypeSplitTest |
/-- tests/elm/src/AppendTypeSplitTest.elm -/
def g_elm_AppendTypeSplitTest : Program := {
name := "AppendTypeSplitTest", source := "tests/elm/src",
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [],
aliases := [],
defs := [
.fn "strs" [] (bin "++" (str "foo") (str "bar")),
.fn "doubled" [pv "n", pv "s"] (ifte (bin "<=" (v "n") (i 0)) (v "s") (ap (v "doubled") [.atexp (.paren (bin "-" (v "n") (i 1))), .atexp (.paren (bin "++" (v "s") (v "s")))])),
.fn "ropeStr" [] (bin "++" (ap (v "doubled") [i 16, str "a"]) (ap (v "doubled") [i 16, str "b"])),
.fn "ropeStr2" [] (bin "++" (ap (v "doubled") [i 16, str "a"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 15, str "b"]) (ap (v "doubled") [i 15, str "b"]))))),
.fn "ropeStrLastC" [] (bin "++" (ap (v "doubled") [i 16, str "a"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 15, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 14, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 13, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 12, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 11, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 10, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 9, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 8, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 7, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 6, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 5, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 4, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 3, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 2, str "b"]) (.atexp (.paren (bin "++" (ap (v "doubled") [i 1, str "b"]) (.atexp (.paren (bin "++" (str "b") (str "c")))))))))))))))))))))))))))))))))))))))))))))))))),
.fn "lists" [] (bin "++" (listE [i 1, i 2]) (listE [i 3, i 4])),
.fn "chunkAppend" [] (bin "++" (listE [bin "*" (i 1) (i 2), bin "*" (i 2) (i 2), bin "*" (i 3) (i 2)]) (listE [i 1])),
.fn "nested" [] (bin "++" (.atexp (.paren (bin "++" (str "ab") (str "cd")))) (str "ef")),
.fn "twice" [pv "x"] (bin "++" (v "x") (v "x")),
.fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "strs", v "strs"]), .pat pw (ap (qv "Debug" "log") [str "strEmptyR", .atexp (.paren (bin "++" (str "foo") (str "")))]), .pat pw (ap (qv "Debug" "log") [str "strEmptyL", .atexp (.paren (bin "++" (str "") (str "foo")))]), .pat pw (ap (qv "Debug" "log") [str "strBothEmpty", .atexp (.paren (bin "++" (str "") (str "")))]), .pat pw (ap (qv "Debug" "log") [str "ropeEq", .atexp (.paren (bin "==" (v "ropeStr") (v "ropeStr2")))]), .pat pw (ap (qv "Debug" "log") [str "ropeNeq", .atexp (.paren (bin "==" (v "ropeStr") (v "ropeStrLastC")))]), .pat pw (ap (qv "Debug" "log") [str "lists", v "lists"]), .pat pw (ap (qv "Debug" "log") [str "listEmptyR", .atexp (.paren (bin "++" (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2))]) (listE [])))]), .pat pw (ap (qv "Debug" "log") [str "listEmptyL", .atexp (.paren (bin "++" (listE []) (listE [.atexp (.scon (.intF 1)), .atexp (.scon (.intF 2))])))]), .pat pw (ap (qv "Debug" "log") [str "listBothEmpty", .atexp (.paren (bin "++" (listE []) (listE [])))]), .pat pw (ap (qv "Debug" "log") [str "chunkAppend", v "chunkAppend"]), .pat pw (ap (qv "Debug" "log") [str "nested", v "nested"]), .pat pw (ap (qv "Debug" "log") [str "polyStr", .atexp (.paren (ap (v "twice") [str "hi"]))]), .pat pw (ap (qv "Debug" "log") [str "polyList", .atexp (.paren (ap (v "twice") [listE [.atexp (.scon (.intF 7))]]))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "strs: \"foobar\"" .string,
chk .check "strEmptyR: \"foo\"" .string,
chk .check "strEmptyL: \"foo\"" .string,
chk .check "strBothEmpty: \"\"" .string,
chk .check "ropeEq: True" .data,
chk .check "ropeNeq: False" .data,
chk .check "lists: [1,2,3,4]" .data,
chk .check "listEmptyR: [1,2]" .data,
chk .check "listEmptyL: [1,2]" .data,
chk .check "listBothEmpty: []" .data,
chk .check "chunkAppend: [2,4,6,1]" .data,
chk .check "nested: \"abcdef\"" .string,
chk .check "polyStr: \"hihi\"" .string,
chk .check "polyList: [7,7]" .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_AppendTypeSplitTest 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_AppendTypeSplitTest 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_AppendTypeSplitTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_AppendTypeSplitTest 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]).