Elm Exactly
Results / elm /

ParenthesesTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:rule s-atexp-parenrule d-atexp-parenrule s-atpat-parenrule d-atpat-parenrule s-ty-parenrule s-exp-atexprule d-exp-atexprule s-pat-atpatrule d-pat-atpat

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
Parentheses around an expression, a pattern or a type change nothing but the grouping.

A Standard Definition of Elm?, rules s-atexp-paren and d-atexp-paren: `(e)` has the type and the
value of `e`; rules s-atpat-paren and d-atpat-paren: `(p)` matches as `p`, and fails as `p`
does; rule s-ty-paren: `(t)` is the type `t`. An atomic expression or pattern stands for a full
one (rules s-exp-atexp, d-exp-atexp, s-pat-atpat, d-pat-atpat). <https://elm-test-suite.netlify.app/standard/rules/d-atexp-paren>

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.
grouped: 9
ungrouped: 7
redundant: 5
nested pattern: [3,0,-1]
parenthesised types: [2,4]

elm-0.19.2

passran in 56 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
grouped: 9
ungrouped: 7
redundant: 5
nested pattern: [3,0,-1]
parenthesised types: [2,4]

elm-0.19.3

passran in 53 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
grouped: 9
ungrouped: 7
redundant: 5
nested pattern: [3,0,-1]
parenthesised types: [2,4]

lamdera-1.5.0

passran in 52 ms
Output
grouped: 9
ungrouped: 7
redundant: 5
nested pattern: [3,0,-1]
parenthesised types: [2,4]

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ParenthesesTest exposing (main)
{-| Parentheses around an expression, a pattern or a type change nothing but the grouping.
A Standard Definition of Elm?, rules s-atexp-paren and d-atexp-paren: `(e)` has the type and the
value of `e`; rules s-atpat-paren and d-atpat-paren: `(p)` matches as `p`, and fails as `p`
does; rule s-ty-paren: `(t)` is the type `t`. An atomic expression or pattern stands for a full
one (rules s-exp-atexp, d-exp-atexp, s-pat-atpat, d-pat-atpat). <https://elm-test-suite.netlify.app/standard/rules/d-atexp-paren>
-}
-- TAGS: elm-spec, s-atexp-paren, d-atexp-paren, s-atpat-paren, d-atpat-paren, s-ty-paren
-- TAGS: s-exp-atexp, d-exp-atexp, s-pat-atpat, d-pat-atpat
-- CHECK: grouped: 9
-- CHECK: ungrouped: 7
-- CHECK: redundant: 5
-- CHECK: nested pattern: [3,0,-1]
-- CHECK: parenthesised types: [2,4]
import Html
inner : Maybe (Maybe Int) -> Int
inner m =
case m of
Just (Just n) ->
n
Just (Nothing) ->
0
(Nothing) ->
-1
doubleAll : (List (Int)) -> (List Int)
doubleAll xs =
case xs of
[] ->
[]
x :: rest ->
(*) 2 x :: doubleAll rest
main =
let
_ =
Debug.log "grouped" ((1 + 2) * 3)
_ =
Debug.log "ungrouped" (1 + 2 * 3)
_ =
Debug.log "redundant" ((((5))))
_ =
Debug.log "nested pattern" [ inner (Just (Just 3)), inner (Just Nothing), inner Nothing ]
_ =
Debug.log "parenthesised types" (doubleAll [ 1, 2 ])
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_ParenthesesTest, in StandardElmMech/Generated/Elm_M.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
grouped99t_elm_ParenthesesTest
ungrouped77t_elm_ParenthesesTest
redundant55t_elm_ParenthesesTest
nested pattern[3,0,-1][3,0,-1]t_elm_ParenthesesTest
parenthesised types[2,4][2,4]t_elm_ParenthesesTest
/-- tests/elm/src/ParenthesesTest.elm -/
def g_elm_ParenthesesTest : Program := {
  name := "ParenthesesTest", source := "tests/elm/src",
  exposing := (.items [.var "main"]), imports := [⟨"Html", "Html", none⟩],
  types := [],
  aliases := [],
  defs := [
    .fn "inner" [pv "m"] (caseOf (v "m") [(pcon "Just" [.paren (pcon "Just" [pv "n"])], v "n"), (pcon "Just" [.paren (P (pcA "Nothing"))], i 0), (P (.paren (P (pcA "Nothing"))), .atexp (neg (A (i 1))))]),
    .fn "doubleAll" [pv "xs"] (caseOf (v "xs") [(P (listP []), listE []), (.cons (P (pv "x")) (P (pv "rest")), bin "::" (ap (.atexp (.op "*")) [i 2, v "x"]) (ap (v "doubleAll") [v "rest"]))]),
    .fn "main" [] (letDefs [.pat pw (ap (qv "Debug" "log") [str "grouped", .atexp (.paren (bin "*" (.atexp (.paren (bin "+" (.atexp (.scon (.intF 1))) (.atexp (.scon (.intF 2)))))) (.atexp (.scon (.intF 3)))))]), .pat pw (ap (qv "Debug" "log") [str "ungrouped", .atexp (.paren (bin "+" (.atexp (.scon (.intF 1))) (bin "*" (.atexp (.scon (.intF 2))) (.atexp (.scon (.intF 3))))))]), .pat pw (ap (qv "Debug" "log") [str "redundant", .atexp (.paren (.atexp (.paren (.atexp (.paren (.atexp (.paren (.atexp (.scon (.intF 5))))))))))]), .pat pw (ap (qv "Debug" "log") [str "nested pattern", listE [ap (v "inner") [.atexp (.paren (ap (c "Just") [.atexp (.paren (ap (c "Just") [i 3]))]))], ap (v "inner") [.atexp (.paren (ap (c "Just") [c "Nothing"]))], ap (v "inner") [c "Nothing"]]]), .pat pw (ap (qv "Debug" "log") [str "parenthesised types", .atexp (.paren (ap (v "doubleAll") [listE [i 1, i 2]]))])] (ap (qv "Html" "text") [str "done"])) ],
  checks := [
    chk .check "grouped: 9" .float,
    chk .check "ungrouped: 7" .float,
    chk .check "redundant: 5" .float,
    chk .check "nested pattern: [3,0,-1]" .data,
    chk .check "parenthesised types: [2,4]" .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_ParenthesesTest 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_ParenthesesTest 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_ParenthesesTest states that the program has a meaning by r:p-program, with both premises, and ident_elm_ParenthesesTest that its specialisation is unique and is the reduced program above, both with no hypothesis about principality.