I want a new Constrained Type Variable,
equalable. It can be filled in by types that
(==) can compare soundly.
Type annotation of the
(==) operator is
a -> a -> Bool. However
(==) can do expected behavior on only a part of types. For instance,
Bytes in the
elm/bytes package makes an unsound behavior that the operation always returns
It is because a value of
Bytes is constructed by
(==) compare values using enumerable properties. The operator returns
False when any enumerable properties aren’t the same between these arguments. A
DataView value doesn’t have any enumerable properties, so the operator never returns
equalable type variable, we can get several advantages. Of course, the Elm compiler will be able to detect the potential of unsound behavior by the
(==) operator. On the other example,
Dict comparable v will be able to replace with
Dict equalable v as a more general type because
comparable is a subset of
What do you think about this proposal?
In a document Basics in elm/core,
In a future release, the compiler will detect when
(==)is used with problematic types and provide a helpful error message.
If it relates to my proposal or there is a plan, please tell me!