"Either A or B" dependency in Cabal

cabal, haskell

Solution

While I haven't verified this, I think you can do it using a flag:

flag someName
  default: True

library
  if flag(someName)
    build-depends:
      zip-archive >= 0.2.3.1,
      binary >= 0.7
  else
    build-depends:
      zip-archive <= 0.2.3,
      binary >= 0.5

The solver will pick the branch that makes the overall constraint problem solvable.

Problem

In one of my packages, I semi-recently added an overly strict dependency version constraint to work around a bug in that particular version of the package. However, as new versions of other packages have been released, this is now causing dependency conflicts for some of my users. One of them helpfully suggested to replace the current, overly strict, constraint `zip-archive == 0.2` with something along the lines of `(zip-archive <= 0.2.3 && binary >= 0.5) || (zip-archive >= 0.2.3.1 && binary >= 0.7)` - that is, depend either on A or on B, and we don't really care which one. Is there a way to express this in Cabal?

Original source