basvandijk / scientific

Arbitrary-precision floating-point numbers represented using scientific notation
BSD 3-Clause "New" or "Revised" License
73 stars 40 forks source link

Add Generic instances for Scientific. #27

Closed nc6 closed 9 years ago

nc6 commented 9 years ago

Generic makes it much easier to derive things like an Aeson representation, or a Binary representation. Generics are now in GHC base, so provided we are using recent GHC we get them effectively for free.

nc6 commented 9 years ago

Just spotted issue #24, which this would help with!

basvandijk commented 9 years ago

Hi Nicholas, right now the Scientific type is abstract. This is a good thing because it allows me to change the representation (which I'm planning to do in #26) without me having to worry about breaking user code.

Deriving a Generic instance makes Scientific non-abstract because you can now deconstruct and construct a Scientific using from and to. I would like to keep Scientific abstract unless somebody can convince me otherwise.

Also note that aeson already has ToJSON and FromJSON instances for Scientific.

With regards to #24 I think the best thing would be to add a manual Binary instance to scientific or binary.