Add comparable typevar constraints #229
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Created by: radrow
Currently all types can be combined with
==
and=<
-like relation operators. While this works cool on ints, strings and possibly some other types, it seems to be completely useless for custom ADTs and functions. In my opinion the expression((x, y) => x) == ((x, y) => y)
shouldn't typecheck, as it may lead to hard to find bugs.Another example:
FixedTTL(x) > FixedTTL(y)
works as expected comparingx > y
, but if we accidentally compareFixedTTL
andRelativeTTL
the first one will be always greater, no matter of the arguments.To solve this issue I propose adding qualification to typevars (similar to typeclasses, but restricted only to
Ord
andEq
):The new syntax opens another way of dealing with it:
I think this is the place where we could accept operator overloading. Although in situations where
==
can be derived automatically it is usually the best and the only solution, the<
like operators can be more tricky so we could let the users define the comparison by themselves. Of course not stateful nor payable.