Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Data.Binary instance for Data.Time.Calendar.Day?

Tags:

haskell

Is there a Data.Binary instance for Data.Time.Calendar.Day?

More generally, what is one supposed to do if Data.Binary have not been provided for a particular datatype in a widely used library?

like image 982
Tom Ellis Avatar asked Mar 22 '26 01:03

Tom Ellis


1 Answers

If you just create a Binary instance and place it in your module then you'll be creating an orphan instance which can cause a lot of confusion later when someone imports your module---it'll drag along that orphan instance and possibly conflict with their understanding of how dates should be made Binary.

If you have a very canonical instance, try pushing it to the library author. It's easy to add the instance if it's a good idea and it can benefit anyone who uses that library.

If that isn't an option (or if you have a non-canonical instance) then you probably want to create a newtype wrapper. They're "free" in that the compiler deletes them automatically, but they allow a type to take on an entirely new identity with new typeclass instances.

I've done this before to handle particular parses of, for instance, "dates in this format" compared to Date broadly.

like image 176
J. Abrahamson Avatar answered Mar 24 '26 15:03

J. Abrahamson