on master help sign in
Ambiguous default for MonadExcept
commit150f485e1657512b44696b2d84768969ecb54f2d authorIndex Int <vlad.z.4096@gmail.com> dateSat 30 Apr 2016, 19:10 (10 years ago) parent47b2ec6
7 files changed+47−82
ether.cabal−1 src/Control/Monad/Ether/Ambiguous.hs+1−1 src/Control/Monad/Ether/Ambiguous/Except.hs−55 src/Control/Monad/Ether/Except.hs+22−7 src/Control/Monad/Ether/Except/Class.hs+6−4 src/Control/Monad/Ether/Implicit/Except.hs+1−1 src/Control/Monad/Trans/Ether/Except.hs+17−13
ether.cabal−1
@@ -58,7 +58,6 @@ library
5858 Control.Monad.Ether.Ambiguous.State
5959 Control.Monad.Ether.Ambiguous.State.Lazy
6060 Control.Monad.Ether.Ambiguous.State.Strict
61− Control.Monad.Ether.Ambiguous.Except
6261
6362 build-depends: base >=4.7 && <4.10
6463 , transformers >=0.4.2
src/Control/Monad/Ether/Ambiguous.hs+1−1
@@ -9,5 +9,5 @@ import Control.Monad.Fix as X
99import Control.Monad.Ether.Reader as X
1010import Control.Monad.Ether.Writer as X
1111import Control.Monad.Ether.Ambiguous.State as X
12−import Control.Monad.Ether.Ambiguous.Except as X
12+import Control.Monad.Ether.Except as X
1313import 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 #-}
14{-# LANGUAGE MagicHash #-}
25
36-- | See "Control.Monad.Except".
@@ -5,7 +8,9 @@
58module Control.Monad.Ether.Except
69 (
710 -- * MonadExcept class
8− MonadExcept(..)
11+ MonadExcept
12+ , throw
13+ , catch
914 -- * The Except monad
1015 , Except
1116 , runExcept
@@ -18,15 +23,25 @@ module Control.Monad.Ether.Except
1823 , handle
1924 ) where
2025
21−import GHC.Prim (Proxy#)
22−import Control.Monad.Ether.Except.Class
26+import GHC.Prim (Proxy#, proxy#)
27+import Control.Monad.Ether.Except.Class (MonadExcept)
28+import qualified Control.Monad.Ether.Except.Class as C
2329import Control.Monad.Trans.Ether.Except hiding (throw, catch)
2430import Data.Functor.Identity (Identity(..))
2531
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+
2641-- | Runs an 'Except' and handles the exception with the given function.
27−handle :: Proxy# tag -> (e -> a) -> Except tag e a -> a
28−handle t h m = runIdentity (handleT t h m)
42+handle :: forall tag e a . (e -> a) -> Except tag e a -> a
43+handle h m = runIdentity (handleT @tag h m)
2944
3045-- | 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
32−handleT t h m = fmap (either h id) (runExceptT t m)
46+handleT :: forall tag e m a . Functor m => (e -> a) -> ExceptT tag e m a -> m a
47+handleT h m = fmap (either h id) (runExceptT @tag m)
src/Control/Monad/Ether/Except/Class.hs+6−4
@@ -4,13 +4,15 @@
44{-# LANGUAGE FunctionalDependencies #-}
55{-# LANGUAGE TypeFamilies #-}
66{-# LANGUAGE PolyKinds #-}
7+{-# LANGUAGE TypeApplications #-}
8+{-# LANGUAGE ScopedTypeVariables #-}
79{-# LANGUAGE MagicHash #-}
810
911-- | See "Control.Monad.Except".
1012
1113module Control.Monad.Ether.Except.Class
12− ( MonadExcept(..)
13− ) where
14+ ( MonadExcept(..)
15+ ) where
1416
1517import GHC.Prim (Proxy#)
1618import qualified Control.Monad.Trans.Ether.Except as E
@@ -27,8 +29,8 @@ class Monad m => MonadExcept tag e m | m tag -> e where
2729 catch :: Proxy# tag -> m a -> (e -> m a) -> m a
2830
2931instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
30− throw = E.throw
31− catch = E.catch
32+ throw _ = E.throw @tag
33+ catch _ = E.catch @tag
3234
3335instance {-# OVERLAPPABLE #-}
3436 ( Lift.LiftCatch t
src/Control/Monad/Ether/Implicit/Except.hs+1−1
@@ -22,7 +22,7 @@ module Control.Monad.Ether.Implicit.Except
2222 , handleT
2323 ) where
2424
25−import qualified Control.Monad.Ether.Ambiguous.Except as A
25+import qualified Control.Monad.Ether.Except as A
2626
2727-- | See 'Control.Monad.Ether.Except.MonadExcept'.
2828type MonadExcept e = A.MonadExcept e e
src/Control/Monad/Trans/Ether/Except.hs+17−13
@@ -6,6 +6,9 @@
66{-# LANGUAGE DataKinds #-}
77{-# LANGUAGE PolyKinds #-}
88{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9+{-# LANGUAGE AllowAmbiguousTypes #-}
10+{-# LANGUAGE TypeApplications #-}
11+{-# LANGUAGE ScopedTypeVariables #-}
912{-# LANGUAGE MagicHash #-}
1013
1114-- | See "Control.Monad.Trans.Except".
@@ -25,7 +28,6 @@ module Control.Monad.Trans.Ether.Except
2528 , catch
2629 ) where
2730
28−import GHC.Prim (Proxy#)
2931import Data.Functor.Identity (Identity(..))
3032import qualified Control.Monad.Trans.Except as Trans
3133import Control.Monad.Trans.Ether.Tagged
@@ -40,8 +42,8 @@ import Control.Monad.Trans.Ether.Tagged
4042type Except tag e = ExceptT tag e Identity
4143
4244-- | Runs an 'Except' and returns either an exception or a normal value.
43−runExcept :: Proxy# tag -> Except tag e a -> Either e a
44−runExcept _ = Trans.runExcept . unpack
45+runExcept :: forall tag e a . Except tag e a -> Either e a
46+runExcept = Trans.runExcept . unpack
4547
4648-- | The exception monad transformer.
4749--
@@ -50,22 +52,24 @@ runExcept _ = Trans.runExcept . unpack
5052type ExceptT tag e = TaggedTrans tag (Trans.ExceptT e)
5153
5254-- | Constructor for computations in the exception monad transformer.
53−exceptT :: Proxy# tag -> m (Either e a) -> ExceptT tag e m a
54−exceptT _ = pack . Trans.ExceptT
55+exceptT :: forall tag e m a . m (Either e a) -> ExceptT tag e m a
56+exceptT = pack . Trans.ExceptT
5557
5658-- | Constructor for computations in the exception monad
5759-- (the inverse of 'runExcept').
58−except :: Monad m => Proxy# tag -> Either e a -> ExceptT tag e m a
59−except t = exceptT t . return
60+except :: forall tag e m a . Monad m => Either e a -> ExceptT tag e m a
61+except = exceptT @tag . return
6062
6163-- | 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)
63−runExceptT _ = Trans.runExceptT . unpack
64+runExceptT :: forall tag e m a . ExceptT tag e m a -> m (Either e a)
65+runExceptT = Trans.runExceptT . unpack
6466
6567-- | Is used within a monadic computation to begin exception processing.
66−throw :: Monad m => Proxy# tag -> e -> ExceptT tag e m a
67−throw _ = pack . Trans.throwE
68+throw :: forall tag e m a . Monad m => e -> ExceptT tag e m a
69+throw = pack . Trans.throwE
6870
6971-- | A handler function to handle previous exceptions and return to normal execution.
70−catch :: Monad m => Proxy# tag -> 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)
72+catch
73+ :: forall tag e m a . Monad m
74+ => ExceptT tag e m a -> (e -> ExceptT tag e m a) -> ExceptT tag e m a
75+catch m h = pack $ Trans.catchE (unpack m) (unpack . h)