EqualityBoolPapTest
Tags:elm-spec
Checks, in A Standard Definition of Elm?:rule d-atexp-oprule d-app-basic-partialrule d-app-basic-apply
Translated into Lean for the mechanisation of the book: see its Lean translation.
`(==)` partially applied to a `Bool` works as an ordinary predicate passed to the local helpers `map`, `filter` and `any`, written with patterns. `isTrue` is `(==) True` and `isFalse` is `(==) False`. Mapped over `[True, False, True, False]` they give the list itself and its negation; filtering keeps the two matching elements; and `any` is `True` for both, since the list contains each value.
Results
elm-0.19.1
passran in 70 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. isTrueList: [True,False,True,False] isFalseList: [False,True,False,True] filterTrue: [True,True] filterFalse: [False,False] anyTrue: True anyFalse: True
elm-0.19.2
passran in 51 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. isTrueList: [True,False,True,False] isFalseList: [False,True,False,True] filterTrue: [True,True] filterFalse: [False,False] anyTrue: True anyFalse: True
elm-0.19.3
passran in 102 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. anyFalse: True anyTrue: True filterFalse: [False,False] filterTrue: [True,True] isFalseList: [False,True,False,True] isTrueList: [True,False,True,False]
lamdera-1.5.0
passran in 55 msOutput
anyFalse: True anyTrue: True filterFalse: [False,False] filterTrue: [True,True] isFalseList: [False,True,False,True] isTrueList: [True,False,True,False]
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/EqualityBoolPapTest] in its title.
Source
The -- CHECK: lines give the expected output.
module EqualityBoolPapTest exposing (main)
{-| `(==)` partially applied to a `Bool` works as an ordinary predicate passed
to the local helpers `map`, `filter` and `any`, written with patterns.
`isTrue` is `(==) True` and `isFalse` is `(==) False`. Mapped over `[True,
False, True, False]` they give the list itself and its negation; filtering keeps
the two matching elements; and `any` is `True` for both, since the list
contains each value.
-}
-- TAGS: elm-spec, d-atexp-op, d-app-basic-partial, d-app-basic-apply
-- CHECK: isTrueList: [True,False,True,False]
-- CHECK: isFalseList: [False,True,False,True]
-- CHECK: filterTrue: [True,True]
-- CHECK: filterFalse: [False,False]
-- CHECK: anyTrue: True
-- CHECK: anyFalse: True
import Html exposing (text)
{-| Applies `f` to each element of a list.
-}
map : (a -> b) -> List a -> List b
map f xs =
case xs of
[] ->
[]
x :: rest ->
f x :: map f rest
{-| Keeps the elements of a list for which `keep` holds, in order.
-}
filter : (a -> Bool) -> List a -> List a
filter keep xs =
case xs of
[] ->
[]
x :: rest ->
if keep x then
x :: filter keep rest
else
filter keep rest
{-| Whether `p` holds for some element of a list.
-}
any : (a -> Bool) -> List a -> Bool
any p xs =
case xs of
[] ->
False
x :: rest ->
p x || any p rest
main =
let
isTrue : Bool -> Bool
isTrue = (==) True
isFalse : Bool -> Bool
isFalse = (==) False
bs : List Bool
bs = [ True, False, True, False ]
_ = Debug.log "isTrueList" (map isTrue bs)
_ = Debug.log "isFalseList" (map isFalse bs)
_ = Debug.log "filterTrue" (filter isTrue bs)
_ = Debug.log "filterFalse" (filter isFalse bs)
_ = Debug.log "anyTrue" (any isTrue bs)
_ = Debug.log "anyFalse" (any isFalse bs)
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_core_EqualityBoolPapTest, in StandardElmMech/Generated/ElmCore_CoreIssue115.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 |
|---|---|---|---|
isTrueList | [True,False,True,False] | [True,False,True,False] | t_elm_core_EqualityBoolPapTest |
isFalseList | [False,True,False,True] | [False,True,False,True] | t_elm_core_EqualityBoolPapTest |
filterTrue | [True,True] | [True,True] | t_elm_core_EqualityBoolPapTest |
filterFalse | [False,False] | [False,False] | t_elm_core_EqualityBoolPapTest |
anyTrue | True | True | t_elm_core_EqualityBoolPapTest |
anyFalse | True | True | t_elm_core_EqualityBoolPapTest |
/-- tests/elm-core/src/EqualityBoolPapTest.elm -/
def g_elm_core_EqualityBoolPapTest : Program := {
name := "EqualityBoolPapTest", source := "tests/elm-core/src",
exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", some (.items [.var "text"])⟩],
types := [],
aliases := [],
defs := [
.fn "map" [pv "f", pv "xs"] (caseOf (v "xs") [(P (listP []), listE []), (.cons (P (pv "x")) (P (pv "rest")), bin "::" (ap (v "f") [v "x"]) (ap (v "map") [v "f", v "rest"]))]),
.fn "filter" [pv "keep", pv "xs"] (caseOf (v "xs") [(P (listP []), listE []), (.cons (P (pv "x")) (P (pv "rest")), ifte (ap (v "keep") [v "x"]) (bin "::" (v "x") (ap (v "filter") [v "keep", v "rest"])) (ap (v "filter") [v "keep", v "rest"]))]),
.fn "any" [pv "p", pv "xs"] (caseOf (v "xs") [(P (listP []), c "False"), (.cons (P (pv "x")) (P (pv "rest")), orelse (ap (v "p") [v "x"]) (ap (v "any") [v "p", v "rest"]))]),
.fn "main" [] (letDefs [.fn "isTrue" [] (ap (.atexp (.op "==")) [c "True"]), .fn "isFalse" [] (ap (.atexp (.op "==")) [c "False"]), .fn "bs" [] (listE [c "True", c "False", c "True", c "False"]), .pat pw (ap (qv "Debug" "log") [str "isTrueList", .atexp (.paren (ap (v "map") [v "isTrue", v "bs"]))]), .pat pw (ap (qv "Debug" "log") [str "isFalseList", .atexp (.paren (ap (v "map") [v "isFalse", v "bs"]))]), .pat pw (ap (qv "Debug" "log") [str "filterTrue", .atexp (.paren (ap (v "filter") [v "isTrue", v "bs"]))]), .pat pw (ap (qv "Debug" "log") [str "filterFalse", .atexp (.paren (ap (v "filter") [v "isFalse", v "bs"]))]), .pat pw (ap (qv "Debug" "log") [str "anyTrue", .atexp (.paren (ap (v "any") [v "isTrue", v "bs"]))]), .pat pw (ap (qv "Debug" "log") [str "anyFalse", .atexp (.paren (ap (v "any") [v "isFalse", v "bs"]))])] (ap (v "text") [str "done"])) ],
checks := [
chk .check "isTrueList: [True,False,True,False]" .data,
chk .check "isFalseList: [False,True,False,True]" .data,
chk .check "filterTrue: [True,True]" .data,
chk .check "filterFalse: [False,False]" .data,
chk .check "anyTrue: True" .data,
chk .check "anyFalse: True" .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_core_EqualityBoolPapTest 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_core_EqualityBoolPapTest 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_core_EqualityBoolPapTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_core_EqualityBoolPapTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.