Control.Exception base-3/base-4 woes

Hi, In my CHP library I need to do some exception catching. I want the library to work on GHC 6.8 (with base-3 -- this is the current version in Ubuntu Hardy and Jaunty, for example) and GHC 6.10 (which comes with base-4). But base-3 and base-4 need different code for exception catching (whether it's importing Control.OldException or giving a type to the catch method). Here's what I currently do -- my Haskell file contains this: #if __GLASGOW_HASKELL__ >= 609 import qualified Control.OldException as C #else import qualified Control.Exception as C #endif My cabal file contains this (it used to say just "base,..." but Hackage complained at me the other day when I tried to upload that): Build-Depends: base >= 3 && < 5, ... This works on two machines: one is 6.8+base-3, the other is 6.10+base-3&base-4, where cabal seems to use base-4. However, I have had a bug report (now replicated) which stems from a different 6.10+base-3&base-4 machine where cabal picks base-3 instead. The real problem is that the #if is based on GHC version, but really it should be based on which base-* library is being used. I know the code works with base-3 (use Control.Exception) and base-4 (use Control.OldException) but I can't get the build process right to alter the code based on which base-* library is being used. Can anyone tell me how to fix this? I don't think that changing to always use Control.Exception would fix this, because I need to give a different type for catch in base-3 to base-4, so there's still the incompatibility to be dealt with. Thanks, Neil.

On Fri, Sep 11, 2009 at 11:26 AM, Neil Brown
Can anyone tell me how to fix this? I don't think that changing to always use Control.Exception would fix this, because I need to give a different type for catch in base-3 to base-4, so there's still the incompatibility to be dealt with.
I'd try using a cabal flag to set a CPP flag.
E.g., from cabal
Flag Base3
Description: Use Version 3 of Base
Default: False
Library/Executable
if flag(Base3)
CPP-Options: -D _BASE_3_
Build-Depends: base >= 3 && < 4
else
Build-Depends: base >= 4 && < 5
And then do,
#if _BASE_3_
import qualified Control.Exception as C
#else
import qualified Control.OldException as C
#endif
--
Dave Menendez

On Fri, Sep 11, 2009 at 10:42 AM, David Menendez
On Fri, Sep 11, 2009 at 11:26 AM, Neil Brown
wrote: Can anyone tell me how to fix this? I don't think that changing to always use Control.Exception would fix this, because I need to give a different type for catch in base-3 to base-4, so there's still the incompatibility to be dealt with.
I'd try using a cabal flag to set a CPP flag.
E.g., from cabal
Flag Base3 Description: Use Version 3 of Base Default: False
Library/Executable if flag(Base3) CPP-Options: -D _BASE_3_ Build-Depends: base >= 3 && < 4
else Build-Depends: base >= 4 && < 5
And then do,
#if _BASE_3_ import qualified Control.Exception as C #else import qualified Control.OldException as C #endif
I've had success with this. See: http://hackage.haskell.org/packages/archive/uuid/1.0.2/uuid.cabal Antoine

Neil Brown wrote:
Can anyone tell me how to fix this? I don't think that changing to always use Control.Exception would fix this, because I need to give a different type for catch in base-3 to base-4, so there's still the incompatibility to be dealt with.
http://hackage.haskell.org/package/extensible-exceptions ? Ganesh =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ===============================================================================

Hello Neil, Friday, September 11, 2009, 7:26:47 PM, you wrote: i suggest you to import extensible-exceptions package instead - it's available even for ghc 6.8. alternatively, you may import old-exceptions package (or something like this). trying to develop code compatible with both versions of exceptions should be a nightmare :D
Hi,
In my CHP library I need to do some exception catching. I want the library to work on GHC 6.8 (with base-3 -- this is the current version in Ubuntu Hardy and Jaunty, for example) and GHC 6.10 (which comes with base-4). But base-3 and base-4 need different code for exception catching (whether it's importing Control.OldException or giving a type to the catch method).
Here's what I currently do -- my Haskell file contains this:
#if __GLASGOW_HASKELL__ >= 609 import qualified Control.OldException as C #else import qualified Control.Exception as C #endif
My cabal file contains this (it used to say just "base,..." but Hackage complained at me the other day when I tried to upload that):
Build-Depends: base >= 3 && < 5, ...
This works on two machines: one is 6.8+base-3, the other is 6.10+base-3&base-4, where cabal seems to use base-4. However, I have had a bug report (now replicated) which stems from a different 6.10+base-3&base-4 machine where cabal picks base-3 instead. The real problem is that the #if is based on GHC version, but really it should be based on which base-* library is being used. I know the code works with base-3 (use Control.Exception) and base-4 (use Control.OldException) but I can't get the build process right to alter the code based on which base-* library is being used.
Can anyone tell me how to fix this? I don't think that changing to always use Control.Exception would fix this, because I need to give a different type for catch in base-3 to base-4, so there's still the incompatibility to be dealt with.
Thanks,
Neil. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (5)
-
Antoine Latter
-
Bulat Ziganshin
-
David Menendez
-
Neil Brown
-
Sittampalam, Ganesh