@@ -6,6 +6,7 @@
6{-# LANGUAGE DataKinds #-}
6{-# LANGUAGE DataKinds #-}
7{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9+{-# LANGUAGE MagicHash #-}
10-- | See "Control.Monad.Trans.Except".
11-- | See "Control.Monad.Trans.Except".
@@ -24,6 +25,7 @@ module Control.Monad.Trans.Ether.Except
28+import GHC.Prim (Proxy#)
27import Data.Functor.Identity (Identity(..))
29import Data.Functor.Identity (Identity(..))
28import qualified Control.Monad.Trans.Except as Trans
30import qualified Control.Monad.Trans.Except as Trans
29import Control.Monad.Trans.Ether.Tagged
31import Control.Monad.Trans.Ether.Tagged
@@ -38,7 +40,7 @@ import Control.Monad.Trans.Ether.Tagged
38type Except tag e = ExceptT tag e Identity
40type Except tag e = ExceptT tag e Identity
40-- | Runs an 'Except' and returns either an exception or a normal value.
42-- | Runs an 'Except' and returns either an exception or a normal value.
41−runExcept :: proxy tag -> Except tag e a -> Either e a
43+runExcept :: Proxy# tag -> Except tag e a -> Either e a
42runExcept _ = Trans.runExcept . unpack
44runExcept _ = Trans.runExcept . unpack
44-- | The exception monad transformer.
46-- | The exception monad transformer.
@@ -48,22 +50,22 @@ runExcept _ = Trans.runExcept . unpack
48type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
50type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
50-- | Constructor for computations in the exception monad transformer.
52-- | Constructor for computations in the exception monad transformer.
51−exceptT :: proxy tag -> m (Either e a) -> ExceptT tag e m a
53+exceptT :: Proxy# tag -> m (Either e a) -> ExceptT tag e m a
52exceptT _ = pack . Trans.ExceptT
54exceptT _ = pack . Trans.ExceptT
54-- | Constructor for computations in the exception monad
56-- | Constructor for computations in the exception monad
55-- (the inverse of 'runExcept').
57-- (the inverse of 'runExcept').
56−except :: Monad m => proxy tag -> Either e a -> ExceptT tag e m a
58+except :: Monad m => Proxy# tag -> Either e a -> ExceptT tag e m a
57except t = exceptT t . return
59except t = exceptT t . return
59-- | Runs an 'ExceptT' and returns either an exception or a normal value.
61-- | Runs an 'ExceptT' and returns either an exception or a normal value.
60−runExceptT :: proxy tag -> ExceptT tag e m a -> m (Either e a)
62+runExceptT :: Proxy# tag -> ExceptT tag e m a -> m (Either e a)
61runExceptT _ = Trans.runExceptT . unpack
63runExceptT _ = Trans.runExceptT . unpack
63-- | Is used within a monadic computation to begin exception processing.
65-- | Is used within a monadic computation to begin exception processing.
64−throw :: Monad m => proxy tag -> e -> ExceptT tag e m a
66+throw :: Monad m => Proxy# tag -> e -> ExceptT tag e m a
65throw _ = pack . Trans.throwE
67throw _ = pack . Trans.throwE
67-- | A handler function to handle previous exceptions and return to normal execution.
69-- | A handler function to handle previous exceptions and return to normal execution.
68−catch :: Monad m => proxy tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
70+catch :: Monad m => Proxy# tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
69catch _ m h = pack $ Trans.catchE (unpack m) (unpack . h)
71catch _ m h = pack $ Trans.catchE (unpack m) (unpack . h)