Good point. Simplicity is what makes Elm very special and fun to use. That’s why I did not propose the ability to define custom typeclasses. In fact, now that you have mentioned reducing Elm’s complexity, I think it should only be possible to extend the number
typeclass. I don’t see any practical use case for extending things like appendable
, and I no longer think there should be a list
typeclass because of how different variants of list have slightly different behavior.
Now I am only proposing the ability to define custom numeric types.
Now that I am thinking of this proposal differently, maybe the syntax for making a custom numeric type should be different.
Declaring that a type is a numeric type would look like this:
numeric type Fraction =
{ ... }
Numeric types have to implement five functions: addition, subtraction, multiplication, division, and compare. Maybe the syntax for defining these functions could look something like this:
mumeric add : Fraction -> Fraction -> Fraction
fraction1 + fraction2 =
-- ...
numeric compare : Fraction -> Fraction -> Order
compare fraction2 fraction2 =
-- ...