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

Travis Cardwell travis.cardwell at extrema.is
Thu Jun 3 10:01:23 UTC 2021

On Thu, Jun 3, 2021 at 6:18 PM Henning Thielemann 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.

Indeed.  It seems that I have forgotten to put a prominent warning about
usage of those instances.

In the past, I have used TTC in applications, avoiding using it in
(shared) libraries.  In shared libraries, I simply define "render" and
"parse" functions using the most appropriate textual types.
Applications can then define (orphan) instances of Render and Parse as
simple wrappers around the functions exposed by the library.  By only
defining instances in the leaves of the dependency hierarchy, one does
not run into conflicts.

Very recently, I have started to use TTC in libraries as well, however,
in cases where I would otherwise have to duplicate functionality that
TTC provides.  I had planned on advising not using TTC in libraries, but
I ended up deciding to not do so.

Frankly, I have never used Data.TTC.Instances myself.  I included it in
an attempt to provide convenience for others.  It is indeed extremely
inconvenient if a shared library imports the instances, and that is
possible->probable even with a prominent warning against doing so.
Perhaps it would be best to remove the Data.TTC.Instances module as well
as add a prominent warning against declaring orphan instances,
especially in a shared library.

Thank you very much for the feedback!  I really appreciate it!

Best regards,


More information about the Haskell-Cafe mailing list