``Orphan instances'' should be avoided anyway.
kahl at cas.mcmaster.ca
kahl at cas.mcmaster.ca
Tue Aug 12 13:38:28 EDT 2008
Henning Thielemann <lemming at henning-thielemann.de> wrote:
>
> On Tue, 12 Aug 2008 kahl at cas.mcmaster.ca wrote:
>
> > I just would like to point out that there is nothing inherently bad about
> > what GHC calls ``orphan instances''.
> >
> > From a code structuring point of view,
> > I frequently ``consider orphan'' instances
> > useful for separation of concerns.
>
> The problem is, that if you have a main instance of a class for a type and
> this one is not bundled with either the type or the class, then you are
> able to import the type and the class without the main instance (that is,
> you can accidentally miss that instance)
Or on purpose --- this is in fact another use of ``orphan instances''
I forgot to mention.
> , and thus you are able to define another instance.
Indeed --- this is the only way to have different instances
for the same class, as long as we do not have something like
the ``named instances'' of our Haskell-2001 paper (shameless plug ;-).
> This will likely cause clash with the main instance
> sooner or later, if other modules import your custom instance and the main
> one.
If there are several instances,
there is very likely no ``main instance''.
Wolfram
More information about the Libraries
mailing list