[Haskell-cafe] [ANN] ttc- - Textual Type Classes

MigMit migmit at gmail.com
Thu Jun 3 09:44:45 UTC 2021

Agreed. I like to use DefaultSignatures like this:

class Parse a where
  parse :: ...
  default parse :: ParseInternal a => ... -- same ... as above
  parse = parseInternal

class ParseInternal a where
  parseInternal :: ... -- again, same ...

instance ParseInternal Double where
  parseInternal = ... -- specific implementation
instance ParseInternal Float where
  parseInternal = ... -- specific implementation

Then all the user needs to do is to say

instance Parse Double

and it would automagically use the provided implementation.

> On 3 Jun 2021, at 11:18, Henning Thielemann <lemming at henning-thielemann.de> wrote:
> On Thu, 3 Jun 2021, Travis Cardwell wrote:
>> On Thu, Jun 3, 2021 at 4:49 PM Henning Thielemann wrote:
>>> On Thu, 3 Jun 2021, Travis Cardwell wrote:
>>>> The Render and Parse type classes in Data.TTC
>>>> have no instances, allowing developers to write their own instances for
>>>> Int for example, but some default instances can optionally be imported
>>>> from Data.TTC.Instances when they are appropriate.
>>> Are these instances orphan?
>> Indeed they are.  I use the following directive to hide the warnings for
>> that module:
>>   {-# OPTIONS_GHC -fno-warn-orphans #-}
> I would not do that. Even orphan instances must be unique. If I would decide to define my own instances but import a library that transitively imports Data.TTC.Instances somewhere, I get a clash. Orphan instances are really only helpful for the case where you need an instance but you neither maintain the class nor the type definition but otherwise are sure that your instance is the one and only.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

More information about the Haskell-Cafe mailing list