Reputation: 15628
According to What does comparable mean in Elm? comparable
is built-in type constraint that can be used to limit type variables to those built-in types that are, well, comparable. The following questions comes to mind (and are not so easy to find out):
f
that accepts List of elements (of a same but uncertain type) each of which can be used as an argument to some function g
(i.e. f
accepts List a
and moreover inst
being of type a
implies that g(inst)
makes sense)Upvotes: 11
Views: 1162
Reputation: 21
From Elm's official guide:
The full list of constrained type variables is:
number
permitsInt
andFloat
appendable
permitsString
andList a
comparable
permitsInt
,Float
,Char
,String
, and lists/tuples of comparable valuescompappend
permitsString
andList comparable
Elm's Guide > Reading Types > Constrained Type Variables
Upvotes: 1
Reputation: 802
Besides comparable
(ints, floats, chars, strings, lists, and tuples) there are also appendable
(strings, text, and lists) and number
(ints and floats). I have not seen an authoritative list (outside of the compiler source).
There is no way to define similar typeclasses of your own.
Yes, this limits what functions you can write. No one has convinced Evan that this limit is a problem.
Upvotes: 11