Tomas Kulich
Tomas Kulich

Reputation: 15628

Type constraints in Elm

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

Upvotes: 11

Views: 1162

Answers (2)

Stefano
Stefano

Reputation: 21

From Elm's official guide:

The full list of constrained type variables is:

  • number permits Int and Float
  • appendable permits String and List a
  • comparable permits Int, Float, Char, String, and lists/tuples of comparable values
  • compappend permits String and List comparable

Elm's Guide > Reading Types > Constrained Type Variables

Upvotes: 1

Fred Yankowski
Fred Yankowski

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

Related Questions