well-typed / cborg

Binary serialisation in the CBOR format
https://hackage.haskell.org/package/cborg
191 stars 86 forks source link

"Instance Bonanza" - add lots of instances #15

Closed thoughtpolice closed 7 years ago

thoughtpolice commented 8 years ago

This package needs some love by adding instances to the Serialise class, which is currently somewhat lackluster. Adding a billion instances is what I like to call "Instance Bonanza", as it goes on for a while.

Essentially, anything within the scope of the Haskell Platform is probably fair game.

Shimuuar commented 8 years ago

I've started to add instances for all base data types.

What data format should newtype wrappers should use? Same format as underlying type or wrap it list?

thoughtpolice commented 8 years ago

What data format should newtype wrappers should use? Same format as underlying type or wrap it list?

I say wrap it, IMO. @dcoutts ?

ghorn commented 8 years ago

+1 wrap it to give newtypes more type safety when deserialising

I changed my mind. The point of newtypes is to have no runtime overhead by having identical runtime representation to the wrapped type.

dcoutts commented 8 years ago

I don't think newtype is special. The question about whether to use the standard constructor pattern or an more compact but non-upgradable representation comes down to the question: could the representation of this type ever possibly change? If the answer is no it cannot ever change then it's ok to use a more compact but non-upgradable representation.

Shimuuar commented 8 years ago

Here is list of missing instances for data types on which package depends:

array

bytestring

text

containers

time

Basically all types. There're a lot of them

ghorn commented 8 years ago

Is the vector package part of the plan?

Shimuuar commented 8 years ago

It is. I've aded missing instances but yet to submit PR.

axman6 commented 8 years ago

Are there currently instances for TypeReps and/or StaticPtrs? these will be needed for cloud haskell's Serializable class (also when's the name of that changing? =)

phadej commented 8 years ago

http://hackage.haskell.org/package/binary-orphans (shameless plug) is a good list of inspiration what instances are good to have. Also CI from case-insensitive

phadej commented 8 years ago

@ghorn, as @thoughtpolice mentioned, If Haskell Platform is the target, then: https://www.haskell.org/platform/contents.html and vector is there.

thoughtpolice commented 8 years ago

Are there currently instances for TypeReps and/or StaticPtrs? these will be needed for cloud haskell's Serializable class (also when's the name of that changing? =)

There are now instances for TypeRep and TyCon. StaticPtrs are looked up by a StaticKey which is just type StaticKey = Fingerprint which is also handled, so, basically, yes this should all be fine.

thoughtpolice commented 8 years ago

There are also now instances for all Data.Semigroup types in GHC 8.0+

thoughtpolice commented 7 years ago

We've implemented a lot of these; Vector is coming up soon now that Duncan merged the ST changes, and I believe the major outliers otherwise are array and some of the time types.

Thus, I'm closing this for now, and individual requests for core instances can be filed as new tickets.