[Haskell-cafe] a poorly thought out suggestion for cabal and packages that have lots of instances

Jeremy Shaw jeremy at n-heptane.com
Mon Mar 15 18:44:30 EDT 2010


There are a number of libraries like syb-with-class, happstack-data, etc,
which provide a new class that potentially has a lot of new instances.

For example, let's say I want a 'Data ctx Text' instance. Where should that

To avoid orphan instances it would need to go in the 'text' package where
Text is defined. But it seems unlikely that I am going to convince the
authors of text to add additional dependencies on things like
syb-with-class, happstack-data, etc, just to satisfy a small number of

A second place to put the instance would be in the syb-with-class package.
They will be orphan instances, but as long as you can't import the Data
class without also getting those instances, it doesn't seem like much could
go wrong.  But now syb-with-class has to depend on all the libraries that it
is going to provide instances for. So, I have just shifted the problem from
one library to another.

A third option is to just define the instance in the library where I want to
use it. But now I have opened up the possibility of conflicting orphan
instances for the type -- which is no good.

A fourth option is to create a new package which contains just the instance.
For example:


This still opens the possibility of conflicting orphan instances. But at
least there is a version that is supposedly the 'official' one.

The problem is that it seems like this might really clutter up hackage?
Also, it is annoying to have to create and maintain and entire new cabal
package just for one single class instance. And if i want to install all the
instances, it would be annoying to have to do 20 different cabal installs.

What might be nicer is if I could have a single project directory that
somehow generated all those instances. And if cabal new how to work with
them as a family.  Something like:

 cabal upload syb-with-class*
 cabal install syb-with-class*

Obviously, I have not really thought this through all the way. I just know
that I am continually wondering what I should do when I want to do something
like add a Text instance for syb-with-class?

If we were to get really experimental I might suggest that when you install
syb-with-class, you don't automatically get all the extra instances by
default. But the package system and compiler would know they exist. So if
you tried to write code that required the missing instance, it would suggest
that you need to install the extra package. This would help reduce instances
of people accidentally creating a conflicting instance. But I am sure it
makes something else horrible happen instead ;)

- jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100315/c8034f02/attachment.html

More information about the Haskell-Cafe mailing list