Elm Exactly
Results / elm-core /

ListMapTemplateMemberTaintTest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Checks that `List.map` applies its callback to the elements from last to
first when the callback calls a `let`-bound sorting function whose comparator
logs.

elm/core defines `List.map` with `List.foldr`, which, on a list this short,
applies the callback to the last element first. The callback calls `sortIt`,
which sorts with `cmp`, a local name for `loggingCompare`, which logs its first
argument. The inner lists are `[1, 1]` and `[2, 2]`, so the number logged names
the list being sorted whichever way the comparator's arguments are ordered: the
expected output is the log for `[2, 2]` immediately followed by the log for
`[1, 1]`, then the unchanged sorted lists.

Results

elm-0.19.1

passran in 105 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
cmp: 2
cmp: 1
sorted: [[1,1],[2,2]]

elm-0.19.2

passran in 73 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
cmp: 2
cmp: 1
sorted: [[1,1],[2,2]]

elm-0.19.3

passran in 84 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
cmp: 2
cmp: 1
sorted: [[1,1],[2,2]]

lamdera-1.5.0

passran in 75 ms
Output
cmp: 2
cmp: 1
sorted: [[1,1],[2,2]]

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module ListMapTemplateMemberTaintTest exposing (main)
{-| Checks that `List.map` applies its callback to the elements from last to
first when the callback calls a `let`-bound sorting function whose comparator
logs.
elm/core defines `List.map` with `List.foldr`, which, on a list this short,
applies the callback to the last element first. The callback calls `sortIt`,
which sorts with `cmp`, a local name for `loggingCompare`, which logs its first
argument. The inner lists are `[1, 1]` and `[2, 2]`, so the number logged names
the list being sorted whichever way the comparator's arguments are ordered: the
expected output is the log for `[2, 2]` immediately followed by the log for
`[1, 1]`, then the unchanged sorted lists.
-}
-- CHECK: cmp: 2
-- CHECK-NEXT: cmp: 1
-- CHECK: sorted: [[1,1],[2,2]]
import Html exposing (text)
loggingCompare : Int -> Int -> Order
loggingCompare a b =
let
_ =
Debug.log "cmp" a
in
compare a b
main : Html.Html msg
main =
let
cmp : Int -> Int -> Order
cmp =
loggingCompare
sortIt : List Int -> List Int
sortIt =
\ys -> List.sortWith cmp ys
sorted =
List.map (\x -> sortIt x) [ [ 1, 1 ], [ 2, 2 ] ]
_ =
Debug.log "sorted" sorted
in
text "done"