Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different imports according to version of dependencies

Tags:

haskell

cabal

I have a module that uses Control.Exception in Base < 4 which is Control.OldException in Base >= 4. How can I, using cabal or any other tool, get rid of the version dependency (just depend on Base and not Base < 4) and import Control.OldException when using Base >= 4 and Control.Exception when using Base < 4?

like image 555
HaskellElephant Avatar asked Feb 24 '23 15:02

HaskellElephant


1 Answers

cabal automatically sets certain CPP definitions based on the version of packages used.

So for your case I would:

{-# LANGUAGE CPP #-}
module Blah where
#if MIN_VERSION_base(0,4,0)
import Control.OldException
#else
import Control.Exception
#endif

This method builds fine with cabal.

(actually, I would use new exceptions and wouldn't bother supporting base < 4, but that's just me)

like image 159
Thomas M. DuBuisson Avatar answered Mar 03 '23 03:03

Thomas M. DuBuisson