[Haskell-cafe] Dependency trickery

Felipe Lessa felipe.lessa at gmail.com
Sun Jan 17 08:52:19 EST 2010

On Sun, Jan 17, 2010 at 10:09:14AM +0000, Andrew Coppin wrote:
> Suppose I write some code that can work with Gtk2hs or wxHaskell.
> How do I go about making that into a package?
> Specifically, how do I make it so that you don't have to install
> Gtk2hs *and* wxHaskell to build it? Do I have to actually make it
> into two seperate packages to do that?

You just need to add a flag 'gtk2hs' and then construct the
Build-Depends depending on the value of the flag.  However, if
e.g. that flag is by default True, then users of wxHaskell will
have to manually change its value.  I.e. it is not automatic
based on what the user has on his system.

> Also, supposing we have another package which requires the first,
> but doesn't care whether it's using Gtk2hs or wxHaskell. How do I do
> that? Obviously the answer depends on what happens in the previous
> step. If I make two seperate packages, for example, and they both
> export the same module, can I just add optional dependancies on
> both? Does Cabal support that?

Just depend on the package :), how the first package was compiled
is out of the scope of the second one.

> Not that I'm attempting to *do* this, you understand. I'd just like
> to know if it's possible...

Another possibility is to factor out your API into an abstract
interface (maybe using type classes).  Then you would have

  secondpackage (depending on firstpackage-base)

But then you only factor your problem to your outmost package,

  myapp (depends on -wx or -gtk depending on a flag)



More information about the Haskell-Cafe mailing list