I\'m having trouble understanding what exactly a comparable
is in Elm. Elm seems as confused as I am.
On the REPL:
> f1 = (<)
&l
UPDATE: thanks to @charlie inputs i include this:
Compare any two comparable values. Comparable values include
String
,Char
,Int
,Float
,Time
, or alist
ortuple
containing comparable values. These are also the only values that work as Dict keys or Set members.
taken from the elm docs: - here
Older version:
Comparable types includes
numbers
,characters
,strings
,~~lists of comparable things
, andtuples of comparable things
. Note that tuples with 7 or more elements are not comparable; why are your tuples so big?
This means that:
[(1,"string"), (2, "another string")]
: List (Int, String)
- is comparable
But having
(1, "string", True)
: (Int, String, Bool)
or
[(1,True), (2, False)]
: List (Int, Bool )
- are not comparable yet.
This issue is discussed here
Note: Usually people encounter problems with the comparable
type when they try to use a union type as a Key in a Dict.
Tags and Constructors of union types are not comparable. So the following doesn't even compile.
type SomeUnion = One | Two | Three
Dict.fromList [ (One, "one related"), (Two, "two related") ] : Dict SomeUnion String
Usually when you try to do this, there is a better approach to your data structure. But until this gets decided - an AllDict can be used.