On 3 Jun 2021, at 11:18, Henning Thielemann <lemming@henning-thielemann.de> wrote:
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.
While this is true, as far as I understand, avoiding orphan instances (be it using MigMit's method below or by directly providing instances in the library) requires that the library that provides the type class (TTC in this case) depend on all packages necessary to even be able to write those instances. While this is clearly not an issue for Base types like Int, Float etc., some libraries seem to have the tendency to provide instances for random data types that require pulling in additional dependencies that no-one in the tree actually needs. As someone who always gets slightly depressed when `cabal install XYZ` gives a multi-screen list of packages to compile, I would like to suggest that providing pre-made instances is cool, as long as that doesn't introduce extra dependencies for the type-class-providing library. How to solve the orphan problem, I also don't know. :) Cheers, Tom On 03/06/2021 11:44, MigMit wrote:
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@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.
_______________________________________________ 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.