Open s-marashi opened 8 years ago
I just stumbled across this same error in a less weird example. I began exploring a strategy for shuffling Lists (incomplete example) and goofed.
import Html exposing (text)
import Random exposing (generate, initialSeed, float, list, Seed)
shuffleList : List Int -> List Int
shuffleList list =
let
randomVals = List.map createFloatAndItemTuple list
sortedListWithTuples = List.sortBy (\itemTuple -> fst itemTuple) randomVals
in
List.map (\itemTuple -> snd itemTuple) sortedListWithTuples
createFloatAndItemTuple num =
let
seed = initialSeed 12345
in
-- Comment out line 17 and uncomment line 18 to see error
(,) 1.2 num
--(,) (generate (float 0 100) seed) num
main =
text "I compile!"
And the error I got:
TYPE MISMATCH The 2nd argument to function
sortBy
is causing a mismatch.8| sortedListWithTuples = List.sortBy (\itemTuple -> fst itemTuple) randomVals Function
sortBy
is expecting the 2nd argument to be:List ( ( Float, Seed ), a )
But it is:
List ( ( Float, Seed ), a )
Hint: Only ints, floats, chars, strings, lists, and tuples are comparable.
I assumed generate
returned a Float, but it returned a (Float, Seed)
. The expected vs. actual in the error message being the same made it a little confusing to troubleshoot.
As I was playing around of comparability an equability concept, I found this weird example:
which fails by this error:
So I think here is a challenge for comparability concept, i.e. although in the compiler's hint is said tuples are comparable but this one is an exception so maybe comparability should be defined as "any composite data structure is comparable if and only if all of its members are comparable" then the mentioned tuple is not comparable at all and then compiler error should be:
or maybe something more declarative.