Closed ocramz closed 2 years ago
It would break Eq
substantivity, for example. Similar reason why Ratio
from base
doesn't have Generic
instance.
Afraid I don't follow. How is the Eq instance related?
It's easy to make instance which would serialize equal Scientific
values to different serialized forms.
It's easy to make instance which would serialize equal
Scientific
values to different serialized forms.
I don't understand why this is a concern. Does the built-in Binary
instance always serialize equal Scientific
values to equal serialized forms? It makes no attempt at normalization, so it seems that it has the same problem that you described. And if Binary
does not have this nice property, why do we care about other types of serialization that are Generic
ally derived? Are there other issues besides normalization that allow two equal Scientific
values to serialize have different encoding? Or, are there plans to fix the Binary
instance?
instance Binary Scientific where
put (Scientific c e) = put c *> put (toInteger e)
get = Scientific <$> get <*> (fromInteger <$> get)
The main concern is that Scientific
is an abstract type. Generic
doesn't fit well. Writing instances by hand is not hard, and then everyone can decide whether normalization is needed or not.
I realize this question might have been asked a number of times already. I don't see a Generic instance, which would be handy when doing serialisation etc.
Thoughts?