Elm Exactly
Results / elm /

InfixAssocRightConsAppendTest

Tags:elm-spec

Checks, in A Standard Definition of Elm?:figure core-fixitiesderived form infixbasis Basics.appendrule s-exp-app

Not translated into Lean for the mechanisation of the book: see why.

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`::` and `++` (both precedence 5) associate to the right, so `"a" ++ "b" :: [ "c" ]` does not type.

A Standard Definition of Elm?, Section 2.7 and Figure 3 (the fixities of the operators of the
initial basis): operators of equal precedence that both associate to the left group to the
left, and both to the right, to the right. <https://elm-test-suite.netlify.app/standard/figures/core-fixities>

The chain is `"a" ++ ("b" :: [ "c" ])`, which appends a list of strings to a string: a type
error. Grouped to the left it would be `("a" ++ "b") :: [ "c" ]`, `["ab","c"]`.

Results

elm-0.19.1

pass
Output
Compiling ...-- TYPE MISMATCH ------------------------- src/InfixAssocRightConsAppendTest.elm

The (++) operator needs the same type of value on both sides:

24|             Debug.log "chain" ("a" ++ "b" :: [ "c" ])
                                   ^^^^^^^^^^^^^^^^^^^^^
I see a String on the left and a List on the right. Which should it be? Does the
string need [] around it to become a list?

Detected problems in 1 module.

elm-0.19.2

pass
Output
Compiling ...-- TYPE MISMATCH ------------------------- src/InfixAssocRightConsAppendTest.elm

The (++) operator needs the same type of value on both sides:

24|             Debug.log "chain" ("a" ++ "b" :: [ "c" ])
                                   ^^^^^^^^^^^^^^^^^^^^^
I see a String on the left and a List on the right. Which should it be? Does the
string need [] around it to become a list?

Detected problems in 1 module.

elm-0.19.3

pass
Output
Compiling ...-- TYPE MISMATCH ------------------------- src/InfixAssocRightConsAppendTest.elm

The (++) operator needs the same type of value on both sides:

24|             Debug.log "chain" ("a" ++ "b" :: [ "c" ])
                                   ^^^^^^^^^^^^^^^^^^^^^
I see a String on the left and a List on the right. Which should it be? Does the
string need [] around it to become a list?

Detected problems in 1 module.

lamdera-1.5.0

pass
Output
Detected problems in 1 module.
-- TYPE MISMATCH ------------------------- src/InfixAssocRightConsAppendTest.elm

The (++) operator needs the same type of value on both sides:

24|             Debug.log "chain" ("a" ++ "b" :: [ "c" ])
                                   ^^^^^^^^^^^^^^^^^^^^^
I see a String on the left and a List on the right. Which should it be? Does the
string need [] around it to become a list?

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module InfixAssocRightConsAppendTest exposing (main)
{-| `::` and `++` (both precedence 5) associate to the right, so `"a" ++ "b" :: [ "c" ]` does not type.
A Standard Definition of Elm?, Section 2.7 and Figure 3 (the fixities of the operators of the
initial basis): operators of equal precedence that both associate to the left group to the
left, and both to the right, to the right. <https://elm-test-suite.netlify.app/standard/figures/core-fixities>
The chain is `"a" ++ ("b" :: [ "c" ])`, which appends a list of strings to a string: a type
error. Grouped to the left it would be `("a" ++ "b") :: [ "c" ]`, `["ab","c"]`.
-}
-- TAGS: elm-spec, fig:core-fixities, df:infix, b:Basics.append, s-exp-app
-- COMPILE-ERROR: a chain that types only when grouped to the left
-- CHECK: TYPE MISMATCH
import Html
main =
let
_ =
Debug.log "chain" ("a" ++ "b" :: [ "c" ])
in
Html.text "done"

Lean translation

No reduced program for Lean's evaluator: the test expects a compile error, so it has no meaning to evaluate. Lean has the program as written, in source syntax, and proves what the static semantics says of it (below). See the Lean mechanisation for which tests are in Lean, and why.

Static semantics: Lean proves that the program as written is not legal, so a compiler must reject it (refuse_elm_InfixAssocRightConsAppendTest, in StandardElmMech/Certs/). The kernel finds a core of the program's typing constraints that has no solution, so no derivation types it (core refutation, plan step 11) (Stat.not_legal_of_coreRefutes). It holds for every derivation, with no hypothesis about principality.