on master help sign in
Ambiguous default for MonadExcept
150f485Index Int
ether.cabal−1
@@ -58,7 +58,6 @@ library
58 Control.Monad.Ether.Ambiguous.State
58 Control.Monad.Ether.Ambiguous.State
59 Control.Monad.Ether.Ambiguous.State.Lazy
59 Control.Monad.Ether.Ambiguous.State.Lazy
60 Control.Monad.Ether.Ambiguous.State.Strict
60 Control.Monad.Ether.Ambiguous.State.Strict
61− Control.Monad.Ether.Ambiguous.Except
62
61
63 build-depends: base >=4.7 && <4.10
62 build-depends: base >=4.7 && <4.10
64 , transformers >=0.4.2
63 , transformers >=0.4.2
src/Control/Monad/Ether/Ambiguous.hs+1−1
@@ -9,5 +9,5 @@ import Control.Monad.Fix as X
9import Control.Monad.Ether.Reader as X
9import Control.Monad.Ether.Reader as X
10import Control.Monad.Ether.Writer as X
10import Control.Monad.Ether.Writer as X
11import Control.Monad.Ether.Ambiguous.State as X
11import Control.Monad.Ether.Ambiguous.State as X
12−import Control.Monad.Ether.Ambiguous.Except as X
12+import Control.Monad.Ether.Except as X
13import Control.Monad.Trans.Ether.Dispatch as X
13import Control.Monad.Trans.Ether.Dispatch as X
src/Control/Monad/Ether/Ambiguous/Except.hsdeleted−55
@@ -1,55 +0,0 @@
1−{-# LANGUAGE AllowAmbiguousTypes #-}
2−{-# LANGUAGE ScopedTypeVariables #-}
3−{-# LANGUAGE MagicHash #-}
4−
5−-- | See "Control.Monad.Ether.Except".
6−
7−module Control.Monad.Ether.Ambiguous.Except
8− (
9− -- * MonadExcept class
10− MonadExcept
11− , throw
12− , catch
13− -- * The Except monad
14− , Except
15− , runExcept
16− -- * The ExceptT monad transformer
17− , ExceptT
18− , exceptT
19− , runExceptT
20− -- * Handle functions
21− , handle
22− , handleT
23− ) where
24−
25−import GHC.Prim (Proxy#, proxy#)
26−import Control.Monad.Ether.Except (MonadExcept, ExceptT, Except)
27−import qualified Control.Monad.Ether.Except as Explicit
28−
29−-- | See 'Control.Monad.Ether.Except.throw'.
30−throw :: forall tag e m a . MonadExcept tag e m => e -> m a
31−throw = Explicit.throw (proxy# :: Proxy# tag)
32−
33−-- | See 'Control.Monad.Ether.Except.catch'.
34−catch :: forall tag e m a . MonadExcept tag e m => m a -> (e -> m a) -> m a
35−catch = Explicit.catch (proxy# :: Proxy# tag)
36−
37−-- | See 'Control.Monad.Ether.Except.runExcept'.
38−runExcept :: forall tag e a . Except tag e a -> Either e a
39−runExcept = Explicit.runExcept proxy#
40−
41−-- | See 'Control.Monad.Ether.Except.exceptT'.
42−exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
43−exceptT = Explicit.exceptT proxy#
44−
45−-- | See 'Control.Monad.Ether.Except.runExceptT'.
46−runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
47−runExceptT = Explicit.runExceptT proxy#
48−
49−-- | See 'Control.Monad.Ether.Except.handle'.
50−handle :: forall tag e a . (e -> a) -> Except tag e a -> a
51−handle = Explicit.handle proxy#
52−
53−-- | See 'Control.Monad.Ether.Except.handleT'.
54−handleT :: forall tag e m a . Functor m => (e -> a) -> ExceptT tag e m a -> m a
55−handleT = Explicit.handleT proxy#
src/Control/Monad/Ether/Except.hs+22−7
@@ -1,3 +1,6 @@
1+{-# LANGUAGE AllowAmbiguousTypes #-}
2+{-# LANGUAGE TypeApplications #-}
3+{-# LANGUAGE ScopedTypeVariables #-}
1{-# LANGUAGE MagicHash #-}
4{-# LANGUAGE MagicHash #-}
2
5
3-- | See "Control.Monad.Except".
6-- | See "Control.Monad.Except".
@@ -5,7 +8,9 @@
5module Control.Monad.Ether.Except
8module Control.Monad.Ether.Except
6 (
9 (
7 -- * MonadExcept class
10 -- * MonadExcept class
8− MonadExcept(..)
11+ MonadExcept
12+ , throw
13+ , catch
9 -- * The Except monad
14 -- * The Except monad
10 , Except
15 , Except
11 , runExcept
16 , runExcept
@@ -18,15 +23,25 @@ module Control.Monad.Ether.Except
18 , handle
23 , handle
19 ) where
24 ) where
20
25
21−import GHC.Prim (Proxy#)
26+import GHC.Prim (Proxy#, proxy#)
27+import Control.Monad.Ether.Except.Class (MonadExcept)
22−import Control.Monad.Ether.Except.Class
28+import qualified Control.Monad.Ether.Except.Class as C
23import Control.Monad.Trans.Ether.Except hiding (throw, catch)
29import Control.Monad.Trans.Ether.Except hiding (throw, catch)
24import Data.Functor.Identity (Identity(..))
30import Data.Functor.Identity (Identity(..))
25
31
32+-- | Is used within a monadic computation to begin exception processing.
33+throw :: forall tag e m a . MonadExcept tag e m => e -> m a
34+throw = C.throw (proxy# :: Proxy# tag)
35+
36+-- | A handler function to handle previous exceptions and return to
37+-- normal execution.
38+catch :: forall tag e m a . MonadExcept tag e m => m a -> (e -> m a) -> m a
39+catch = C.catch (proxy# :: Proxy# tag)
40+
26-- | Runs an 'Except' and handles the exception with the given function.
41-- | Runs an 'Except' and handles the exception with the given function.
27−handle :: Proxy# tag -> (e -> a) -> Except tag e a -> a
42+handle :: forall tag e a . (e -> a) -> Except tag e a -> a
28−handle t h m = runIdentity (handleT t h m)
43+handle h m = runIdentity (handleT @tag h m)
29
44
30-- | Runs an 'ExceptT' and handles the exception with the given function.
45-- | Runs an 'ExceptT' and handles the exception with the given function.
31−handleT :: Functor m => Proxy# tag -> (e -> a) -> ExceptT tag e m a -> m a
46+handleT :: forall tag e m a . Functor m => (e -> a) -> ExceptT tag e m a -> m a
32−handleT t h m = fmap (either h id) (runExceptT t m)
47+handleT h m = fmap (either h id) (runExceptT @tag m)
src/Control/Monad/Ether/Except/Class.hs+6−4
@@ -4,13 +4,15 @@
4{-# LANGUAGE FunctionalDependencies #-}
4{-# LANGUAGE FunctionalDependencies #-}
5{-# LANGUAGE TypeFamilies #-}
5{-# LANGUAGE TypeFamilies #-}
6{-# LANGUAGE PolyKinds #-}
6{-# LANGUAGE PolyKinds #-}
7+{-# LANGUAGE TypeApplications #-}
8+{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE MagicHash #-}
9{-# LANGUAGE MagicHash #-}
8
10
9-- | See "Control.Monad.Except".
11-- | See "Control.Monad.Except".
10
12
11module Control.Monad.Ether.Except.Class
13module Control.Monad.Ether.Except.Class
12− ( MonadExcept(..)
14+ ( MonadExcept(..)
13− ) where
15+ ) where
14
16
15import GHC.Prim (Proxy#)
17import GHC.Prim (Proxy#)
16import qualified Control.Monad.Trans.Ether.Except as E
18import qualified Control.Monad.Trans.Ether.Except as E
@@ -27,8 +29,8 @@ class Monad m => MonadExcept tag e m | m tag -> e where
27 catch :: Proxy# tag -> m a -> (e -> m a) -> m a
29 catch :: Proxy# tag -> m a -> (e -> m a) -> m a
28
30
29instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
31instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
30− throw = E.throw
32+ throw _ = E.throw @tag
31− catch = E.catch
33+ catch _ = E.catch @tag
32
34
33instance {-# OVERLAPPABLE #-}
35instance {-# OVERLAPPABLE #-}
34 ( Lift.LiftCatch t
36 ( Lift.LiftCatch t
src/Control/Monad/Ether/Implicit/Except.hs+1−1
@@ -22,7 +22,7 @@ module Control.Monad.Ether.Implicit.Except
22 , handleT
22 , handleT
23 ) where
23 ) where
24
24
25−import qualified Control.Monad.Ether.Ambiguous.Except as A
25+import qualified Control.Monad.Ether.Except as A
26
26
27-- | See 'Control.Monad.Ether.Except.MonadExcept'.
27-- | See 'Control.Monad.Ether.Except.MonadExcept'.
28type MonadExcept e = A.MonadExcept e e
28type MonadExcept e = A.MonadExcept e e
src/Control/Monad/Trans/Ether/Except.hs+17−13
@@ -6,6 +6,9 @@
6{-# LANGUAGE DataKinds #-}
6{-# LANGUAGE DataKinds #-}
7{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE PolyKinds #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9+{-# LANGUAGE AllowAmbiguousTypes #-}
10+{-# LANGUAGE TypeApplications #-}
11+{-# LANGUAGE ScopedTypeVariables #-}
9{-# LANGUAGE MagicHash #-}
12{-# LANGUAGE MagicHash #-}
10
13
11-- | See "Control.Monad.Trans.Except".
14-- | See "Control.Monad.Trans.Except".
@@ -25,7 +28,6 @@ module Control.Monad.Trans.Ether.Except
25 , catch
28 , catch
26 ) where
29 ) where
27
30
28−import GHC.Prim (Proxy#)
29import Data.Functor.Identity (Identity(..))
31import Data.Functor.Identity (Identity(..))
30import qualified Control.Monad.Trans.Except as Trans
32import qualified Control.Monad.Trans.Except as Trans
31import Control.Monad.Trans.Ether.Tagged
33import Control.Monad.Trans.Ether.Tagged
@@ -40,8 +42,8 @@ import Control.Monad.Trans.Ether.Tagged
40type Except tag e = ExceptT tag e Identity
42type Except tag e = ExceptT tag e Identity
41
43
42-- | Runs an 'Except' and returns either an exception or a normal value.
44-- | Runs an 'Except' and returns either an exception or a normal value.
43−runExcept :: Proxy# tag -> Except tag e a -> Either e a
45+runExcept :: forall tag e a . Except tag e a -> Either e a
44−runExcept _ = Trans.runExcept . unpack
46+runExcept = Trans.runExcept . unpack
45
47
46-- | The exception monad transformer.
48-- | The exception monad transformer.
47--
49--
@@ -50,22 +52,24 @@ runExcept _ = Trans.runExcept . unpack
50type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
52type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
51
53
52-- | Constructor for computations in the exception monad transformer.
54-- | Constructor for computations in the exception monad transformer.
53−exceptT :: Proxy# tag -> m (Either e a) -> ExceptT tag e m a
55+exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
54−exceptT _ = pack . Trans.ExceptT
56+exceptT = pack . Trans.ExceptT
55
57
56-- | Constructor for computations in the exception monad
58-- | Constructor for computations in the exception monad
57-- (the inverse of 'runExcept').
59-- (the inverse of 'runExcept').
58−except :: Monad m => Proxy# tag -> Either e a -> ExceptT tag e m a
60+except :: forall tag e m a . Monad m => Either e a -> ExceptT tag e m a
59−except t = exceptT t . return
61+except = exceptT @tag . return
60
62
61-- | Runs an 'ExceptT' and returns either an exception or a normal value.
63-- | Runs an 'ExceptT' and returns either an exception or a normal value.
62−runExceptT :: Proxy# tag -> ExceptT tag e m a -> m (Either e a)
64+runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
63−runExceptT _ = Trans.runExceptT . unpack
65+runExceptT = Trans.runExceptT . unpack
64
66
65-- | Is used within a monadic computation to begin exception processing.
67-- | Is used within a monadic computation to begin exception processing.
66−throw :: Monad m => Proxy# tag -> e -> ExceptT tag e m a
68+throw :: forall tag e m a . Monad m => e -> ExceptT tag e m a
67−throw _ = pack . Trans.throwE
69+throw = pack . Trans.throwE
68
70
69-- | A handler function to handle previous exceptions and return to normal execution.
71-- | A handler function to handle previous exceptions and return to normal execution.
72+catch
73+ :: forall tag e m a . Monad m
70−catch :: Monad m => Proxy# tag -> ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
74+ => ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
71−catch _ m h = pack $ Trans.catchE (unpack m) (unpack . h)
75+catch m h = pack $ Trans.catchE (unpack m) (unpack . h)