on master help sign in
Proxy-hash for MonadExcept
da8edd9Index Int
ether.cabal+2
@@ -67,6 +67,7 @@ library
67 , transformers-base >=0.4.4
67 , transformers-base >=0.4.4
68 , exceptions >=0.8
68 , exceptions >=0.8
69 , template-haskell >=2.9
69 , template-haskell >=2.9
70+ , ghc-prim >=0.3
70
71
71 default-language: Haskell2010
72 default-language: Haskell2010
72 other-extensions: CPP
73 other-extensions: CPP
@@ -77,6 +78,7 @@ library
77 FlexibleInstances
78 FlexibleInstances
78 FunctionalDependencies
79 FunctionalDependencies
79 GeneralizedNewtypeDeriving
80 GeneralizedNewtypeDeriving
81+ MagicHash
80 MultiParamTypeClasses
82 MultiParamTypeClasses
81 ScopedTypeVariables
83 ScopedTypeVariables
82 TemplateHaskell
84 TemplateHaskell
src/Control/Ether/TH.hs+4−3
@@ -1,4 +1,5 @@
1{-# LANGUAGE TemplateHaskell #-}
1{-# LANGUAGE TemplateHaskell #-}
2+{-# LANGUAGE MagicHash #-}
2{-# LANGUAGE CPP #-}
3{-# LANGUAGE CPP #-}
3
4
4-- | Template Haskell utilities.
5-- | Template Haskell utilities.
@@ -9,7 +10,7 @@ module Control.Ether.TH
9
10
10import qualified Language.Haskell.TH as TH
11import qualified Language.Haskell.TH as TH
11
12
12−import Data.Proxy
13+import GHC.Prim (Proxy#, proxy#)
13
14
14emptyDataDecl :: TH.Name -> TH.DecQ
15emptyDataDecl :: TH.Name -> TH.DecQ
15#if __GLASGOW_HASKELL__ < 800
16#if __GLASGOW_HASKELL__ < 800
@@ -23,8 +24,8 @@ funSimple name body = TH.funD name [ TH.clause [] (TH.normalB body) [] ]
23
24
24proxySimple :: TH.Name -> TH.TypeQ -> TH.Q (TH.Dec, TH.Dec)
25proxySimple :: TH.Name -> TH.TypeQ -> TH.Q (TH.Dec, TH.Dec)
25proxySimple name ty = do
26proxySimple name ty = do
26− sig <- TH.sigD name [t| Proxy $ty |]
27+ sig <- TH.sigD name [t| Proxy# $ty |]
27− val <- funSimple name [e| Proxy |]
28+ val <- funSimple name [e| proxy# |]
28 return (sig, val)
29 return (sig, val)
29
30
30-- |
31-- |
src/Control/Monad/Ether/Except.hs+4−2
@@ -1,3 +1,4 @@
1+{-# LANGUAGE MagicHash #-}
1
2
2-- | See "Control.Monad.Except".
3-- | See "Control.Monad.Except".
3
4
@@ -17,14 +18,15 @@ module Control.Monad.Ether.Except
17 , handle
18 , handle
18 ) where
19 ) where
19
20
21+import GHC.Prim (Proxy#)
20import Control.Monad.Ether.Except.Class
22import Control.Monad.Ether.Except.Class
21import Control.Monad.Trans.Ether.Except hiding (throw, catch)
23import Control.Monad.Trans.Ether.Except hiding (throw, catch)
22import Data.Functor.Identity (Identity(..))
24import Data.Functor.Identity (Identity(..))
23
25
24-- | Runs an 'Except' and handles the exception with the given function.
26-- | Runs an 'Except' and handles the exception with the given function.
25−handle :: proxy tag -> (e -> a) -> Except tag e a -> a
27+handle :: Proxy# tag -> (e -> a) -> Except tag e a -> a
26handle t h m = runIdentity (handleT t h m)
28handle t h m = runIdentity (handleT t h m)
27
29
28-- | Runs an 'ExceptT' and handles the exception with the given function.
30-- | Runs an 'ExceptT' and handles the exception with the given function.
29−handleT :: Functor m => proxy tag -> (e -> a) -> ExceptT tag e m a -> m a
31+handleT :: Functor m => Proxy# tag -> (e -> a) -> ExceptT tag e m a -> m a
30handleT t h m = fmap (either h id) (runExceptT t m)
32handleT t h m = fmap (either h id) (runExceptT t m)
src/Control/Monad/Ether/Except/Class.hs+4−3
@@ -11,6 +11,7 @@
11{-# LANGUAGE FunctionalDependencies #-}
11{-# LANGUAGE FunctionalDependencies #-}
12{-# LANGUAGE TypeFamilies #-}
12{-# LANGUAGE TypeFamilies #-}
13{-# LANGUAGE PolyKinds #-}
13{-# LANGUAGE PolyKinds #-}
14+{-# LANGUAGE MagicHash #-}
14
15
15-- | See "Control.Monad.Except".
16-- | See "Control.Monad.Except".
16
17
@@ -18,19 +19,19 @@ module Control.Monad.Ether.Except.Class
18 ( MonadExcept(..)
19 ( MonadExcept(..)
19 ) where
20 ) where
20
21
22+import GHC.Prim (Proxy#, proxy#)
21import qualified Control.Monad.Trans.Ether.Except as E
23import qualified Control.Monad.Trans.Ether.Except as E
22import qualified Control.Monad.Trans.Lift.Catch as Lift
24import qualified Control.Monad.Trans.Lift.Catch as Lift
23
25
24−
25-- | See 'Control.Monad.Except.MonadError'.
26-- | See 'Control.Monad.Except.MonadError'.
26class Monad m => MonadExcept tag e m | m tag -> e where
27class Monad m => MonadExcept tag e m | m tag -> e where
27
28
28 -- | Is used within a monadic computation to begin exception processing.
29 -- | Is used within a monadic computation to begin exception processing.
29− throw :: proxy tag -> e -> m a
30+ throw :: Proxy# tag -> e -> m a
30
31
31 -- | A handler function to handle previous exceptions and return to
32 -- | A handler function to handle previous exceptions and return to
32 -- normal execution.
33 -- normal execution.
33− catch :: proxy tag -> m a -> (e -> m a) -> m a
34+ catch :: Proxy# tag -> m a -> (e -> m a) -> m a
34
35
35instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
36instance (Monad m, e ~ e') => MonadExcept tag e (E.ExceptT tag e' m) where
36 throw = E.throw
37 throw = E.throw
src/Control/Monad/Ether/Implicit/Except.hs+9−8
@@ -1,5 +1,6 @@
1{-# LANGUAGE ConstraintKinds #-}
1{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE MagicHash #-}
3
4
4-- | See "Control.Monad.Ether.Except".
5-- | See "Control.Monad.Ether.Except".
5
6
@@ -21,7 +22,7 @@ module Control.Monad.Ether.Implicit.Except
21 , handleT
22 , handleT
22 ) where
23 ) where
23
24
24−import Data.Proxy
25+import GHC.Prim (Proxy#, proxy#)
25import qualified Control.Monad.Ether.Except as Explicit
26import qualified Control.Monad.Ether.Except as Explicit
26
27
27-- | See 'Control.Monad.Ether.Except.MonadExcept'.
28-- | See 'Control.Monad.Ether.Except.MonadExcept'.
@@ -29,34 +30,34 @@ type MonadExcept e = Explicit.MonadExcept e e
29
30
30-- | See 'Control.Monad.Ether.Except.throw'.
31-- | See 'Control.Monad.Ether.Except.throw'.
31throw :: forall e m a . MonadExcept e m => e -> m a
32throw :: forall e m a . MonadExcept e m => e -> m a
32−throw = Explicit.throw (Proxy :: Proxy e)
33+throw = Explicit.throw (proxy# :: Proxy# e)
33
34
34-- | See 'Control.Monad.Ether.Except.catch'.
35-- | See 'Control.Monad.Ether.Except.catch'.
35catch :: forall e m a . MonadExcept e m => m a -> (e -> m a) -> m a
36catch :: forall e m a . MonadExcept e m => m a -> (e -> m a) -> m a
36−catch = Explicit.catch (Proxy :: Proxy e)
37+catch = Explicit.catch (proxy# :: Proxy# e)
37
38
38-- | See 'Control.Monad.Ether.Except.Except'.
39-- | See 'Control.Monad.Ether.Except.Except'.
39type Except e = Explicit.Except e e
40type Except e = Explicit.Except e e
40
41
41-- | See 'Control.Monad.Ether.Except.runExcept'.
42-- | See 'Control.Monad.Ether.Except.runExcept'.
42runExcept :: Except e a -> Either e a
43runExcept :: Except e a -> Either e a
43−runExcept = Explicit.runExcept Proxy
44+runExcept = Explicit.runExcept proxy#
44
45
45-- | See 'Control.Monad.Ether.Except.ExceptT'.
46-- | See 'Control.Monad.Ether.Except.ExceptT'.
46type ExceptT e = Explicit.ExceptT e e
47type ExceptT e = Explicit.ExceptT e e
47
48
48-- | See 'Control.Monad.Ether.Except.exceptT'.
49-- | See 'Control.Monad.Ether.Except.exceptT'.
49exceptT :: m (Either e a) -> ExceptT e m a
50exceptT :: m (Either e a) -> ExceptT e m a
50−exceptT = Explicit.exceptT Proxy
51+exceptT = Explicit.exceptT proxy#
51
52
52-- | See 'Control.Monad.Ether.Except.runExceptT'.
53-- | See 'Control.Monad.Ether.Except.runExceptT'.
53runExceptT :: ExceptT e m a -> m (Either e a)
54runExceptT :: ExceptT e m a -> m (Either e a)
54−runExceptT = Explicit.runExceptT Proxy
55+runExceptT = Explicit.runExceptT proxy#
55
56
56-- | See 'Control.Monad.Ether.Except.handle'.
57-- | See 'Control.Monad.Ether.Except.handle'.
57handle :: (e -> a) -> Except e a -> a
58handle :: (e -> a) -> Except e a -> a
58−handle = Explicit.handle Proxy
59+handle = Explicit.handle proxy#
59
60
60-- | See 'Control.Monad.Ether.Except.handleT'.
61-- | See 'Control.Monad.Ether.Except.handleT'.
61handleT :: Functor m => (e -> a) -> ExceptT e m a -> m a
62handleT :: Functor m => (e -> a) -> ExceptT e m a -> m a
62−handleT = Explicit.handleT Proxy
63+handleT = Explicit.handleT proxy#
src/Control/Monad/Trans/Ether/Dispatch.hs+6−4
@@ -13,6 +13,7 @@
13{-# LANGUAGE DataKinds #-}
13{-# LANGUAGE DataKinds #-}
14{-# LANGUAGE PolyKinds #-}
14{-# LANGUAGE PolyKinds #-}
15{-# LANGUAGE GeneralizedNewtypeDeriving #-}
15{-# LANGUAGE GeneralizedNewtypeDeriving #-}
16+{-# LANGUAGE MagicHash #-}
16
17
17{- |
18{- |
18
19
@@ -67,6 +68,7 @@ import Control.Monad.Catch (MonadThrow, MonadCatch, MonadMask)
67import GHC.Generics (Generic)
68import GHC.Generics (Generic)
68import Data.Coerce (coerce)
69import Data.Coerce (coerce)
69import Data.Proxy
70import Data.Proxy
71+import GHC.Prim (Proxy#, proxy#)
70
72
71import qualified Control.Monad.Base as MB
73import qualified Control.Monad.Base as MB
72import qualified Control.Monad.Trans.Control as MC
74import qualified Control.Monad.Trans.Control as MC
@@ -173,8 +175,8 @@ instance MonadState tag s m
173
175
174instance MonadExcept tag e m
176instance MonadExcept tag e m
175 => Class.MonadError e (DispatchTagAttachT tag m) where
177 => Class.MonadError e (DispatchTagAttachT tag m) where
176− throwError = let t = Proxy :: Proxy tag in Lift.lift . throw t
178+ throwError = let t = proxy# :: Proxy# tag in Lift.lift . throw t
177− catchError = let t = Proxy :: Proxy tag in Lift.liftCatch (catch t)
179+ catchError = let t = proxy# :: Proxy# tag in Lift.liftCatch (catch t)
178
180
179instance MonadWriter tag w m
181instance MonadWriter tag w m
180 => Class.MonadWriter w (DispatchTagAttachT tag m) where
182 => Class.MonadWriter w (DispatchTagAttachT tag m) where
@@ -198,8 +200,8 @@ instance MonadState tNew s m
198
200
199instance MonadExcept tNew e m
201instance MonadExcept tNew e m
200 => MonadExcept tOld e (DispatchTagReplaceT tOld tNew m) where
202 => MonadExcept tOld e (DispatchTagReplaceT tOld tNew m) where
201− throw _ = let t = Proxy :: Proxy tNew in Lift.lift . throw t
203+ throw _ = let t = proxy# :: Proxy# tNew in Lift.lift . throw t
202− catch _ = let t = Proxy :: Proxy tNew in Lift.liftCatch (catch t)
204+ catch _ = let t = proxy# :: Proxy# tNew in Lift.liftCatch (catch t)
203
205
204instance MonadWriter tNew w m
206instance MonadWriter tNew w m
205 => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
207 => MonadWriter tOld w (DispatchTagReplaceT tOld tNew m) where
src/Control/Monad/Trans/Ether/Except.hs+8−6
@@ -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 #-}
9
10
10-- | See "Control.Monad.Trans.Except".
11-- | See "Control.Monad.Trans.Except".
11
12
@@ -24,6 +25,7 @@ module Control.Monad.Trans.Ether.Except
24 , catch
25 , catch
25 ) where
26 ) where
26
27
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
39
41
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
43
45
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)
49
51
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
53
55
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
58
60
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
62
64
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
66
68
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)