[Haskell-cafe] Data declaration vs type classes

Erik Hesselink hesselink at gmail.com
Fri Jan 8 11:29:46 UTC 2016

On 8 January 2016 at 12:26, Imants Cekusins <imantc at gmail.com> wrote:
>> it's very hard to pass them around, manipulate them and compute with them without using non-standard and awkward techniques.
> well here is one simple use case when class is very convenient:
> class ConvertByteString a where
>   toByteString::a -> ByteString
>   fromByteString::ByteString -> a
> no problems defining instances of this class, passing and calling them
> whatsoever.

One problem with this class would be if you convert String or Text:
what encoding would you use? Probably UTF8, but there are others, and
if you need those you need a newtype at least.


More information about the Haskell-Cafe mailing list