9
votes

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):

  • what are the other type constraints that currently exists in Elm? Is there a list somewhere?
  • Is there a way how I can create my own type constraints? I presume that the answer is no, since Elm does not have any mechanism such as Haskell Typeclasses right now?
  • If the above is true (no custom type constraints), that does mean that the polymorphism is quite limited in Elm, doesn't it? For example, it seems that the following is not achievable right now: I want to create a function 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)
1
Have you seen these two issues regarding type classes?pdexter
Yes, I saw both these. OTOH, I saw there is a concept such as comparable, so I wasn't sure, what's the status of this in Elm.Tomas Kulich

1 Answers

9
votes

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.