on develop help sign in
Merge pull request #439 from reflex-frp/mfunctor-instances

Add mmorph MFunctor instances

commit41add8546127f60531cb07777062a454446b935e authorElliot Cameron <3noch@users.noreply.github.com> dateTue 30 Jun 2020, 10:58 (6 years ago) parent38468bc6a3b805
6 files changed+47−12
reflex.cabal+1 src/Reflex/BehaviorWriter/Base.hs+13−4 src/Reflex/DynamicWriter/Base.hs+13−4 src/Reflex/EventWriter/Base.hs+12−4 src/Reflex/Query/Base.hs+4 src/Reflex/Requester/Base.hs+4
reflex.cabal+1
@@ -80,6 +80,7 @@ library
8080 dependent-map >= 0.3 && < 0.5,
8181 exception-transformers == 0.4.*,
8282 lens >= 4.7 && < 5,
83+ mmorph >= 1.0 && < 1.2,
8384 monad-control >= 1.0.1 && < 1.1,
8485 mtl >= 2.1 && < 2.3,
8586 patch >= 0.0.1 && < 0.1,
src/Reflex/BehaviorWriter/Base.hs+13−4
@@ -24,6 +24,7 @@ module Reflex.BehaviorWriter.Base
2424import Control.Monad.Exception
2525import Control.Monad.Identity
2626import Control.Monad.IO.Class
27+import Control.Monad.Morph
2728import Control.Monad.Reader
2829import Control.Monad.Ref
2930import Control.Monad.State.Strict
@@ -48,7 +49,18 @@ import Reflex.TriggerEvent.Class
4849
4950-- | A basic implementation of 'BehaviorWriter'.
5051newtype BehaviorWriterT t w m a = BehaviorWriterT { unBehaviorWriterT :: StateT [Behavior t w] m a }
51− deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadAsyncException, MonadException) -- The list is kept in reverse order
52+ -- The list is kept in reverse order
53+ deriving
54+ ( Functor
55+ , Applicative
56+ , Monad
57+ , MonadTrans
58+ , MFunctor
59+ , MonadIO
60+ , MonadFix
61+ , MonadAsyncException
62+ , MonadException
63+ )
5264
5365-- | Run a 'BehaviorWriterT' action. The behavior writer output will be provided
5466-- along with the result of the action.
@@ -73,9 +85,6 @@ withBehaviorWriterT f dw = do
7385deriving instance MonadHold t m => MonadHold t (BehaviorWriterT t w m)
7486deriving instance MonadSample t m => MonadSample t (BehaviorWriterT t w m)
7587
76−instance MonadTrans (BehaviorWriterT t w) where
77− lift = BehaviorWriterT . lift
78−
7988instance MonadRef m => MonadRef (BehaviorWriterT t w m) where
8089 type Ref (BehaviorWriterT t w m) = Ref m
8190 newRef = lift . newRef
src/Reflex/DynamicWriter/Base.hs+13−4
@@ -22,6 +22,7 @@ module Reflex.DynamicWriter.Base
2222import Control.Monad.Exception
2323import Control.Monad.Identity
2424import Control.Monad.IO.Class
25+import Control.Monad.Morph
2526import Control.Monad.Primitive
2627import Control.Monad.Reader
2728import Control.Monad.Ref
@@ -51,9 +52,6 @@ import Reflex.Query.Class
5152import Reflex.Requester.Class
5253import Reflex.TriggerEvent.Class
5354
54−instance MonadTrans (DynamicWriterT t w) where
55− lift = DynamicWriterT . lift
56−
5755mapIncrementalMapValues :: (Reflex t, Patch (p v), Patch (p v'), PatchTarget (p v) ~ f v, PatchTarget (p v') ~ f v', Functor p, Functor f) => (v -> v') -> Incremental t (p v) -> Incremental t (p v')
5856mapIncrementalMapValues f = unsafeMapIncremental (fmap f) (fmap f)
5957
@@ -90,7 +88,18 @@ mergeDynIncrementalWithMove a = unsafeBuildIncremental (mapM (sample . current)
9088
9189-- | A basic implementation of 'DynamicWriter'.
9290newtype DynamicWriterT t w m a = DynamicWriterT { unDynamicWriterT :: StateT [Dynamic t w] m a }
93− deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadAsyncException, MonadException) -- The list is kept in reverse order
91+ -- The list is kept in reverse order
92+ deriving
93+ ( Functor
94+ , Applicative
95+ , Monad
96+ , MonadTrans
97+ , MFunctor
98+ , MonadIO
99+ , MonadFix
100+ , MonadAsyncException
101+ , MonadException
102+ )
94103
95104deriving instance MonadHold t m => MonadHold t (DynamicWriterT t w m)
96105deriving instance MonadSample t m => MonadSample t (DynamicWriterT t w m)
src/Reflex/EventWriter/Base.hs+12−4
@@ -35,6 +35,7 @@ import Reflex.TriggerEvent.Class
3535
3636import Control.Monad.Exception
3737import Control.Monad.Identity
38+import Control.Monad.Morph
3839import Control.Monad.Primitive
3940import Control.Monad.Reader
4041import Control.Monad.Ref
@@ -97,7 +98,17 @@ data EventWriterState t w = EventWriterState
9798
9899-- | A basic implementation of 'EventWriter'.
99100newtype EventWriterT t w m a = EventWriterT { unEventWriterT :: StateT (EventWriterState t w) m a }
100− deriving (Functor, Applicative, Monad, MonadFix, MonadIO, MonadException, MonadAsyncException)
101+ deriving
102+ ( Functor
103+ , Applicative
104+ , Monad
105+ , MonadTrans
106+ , MFunctor
107+ , MonadFix
108+ , MonadIO
109+ , MonadException
110+ , MonadAsyncException
111+ )
101112
102113-- | Run a 'EventWriterT' action.
103114runEventWriterT :: forall t m w a. (Reflex t, Monad m, Semigroup w) => EventWriterT t w m a -> m (a, Event t w)
@@ -117,9 +128,6 @@ instance (Reflex t, Monad m, Semigroup w) => EventWriter t w (EventWriterT t w m
117128 , _eventWriterState_told = (tellId myId :=> w) : _eventWriterState_told old
118129 }
119130
120−instance MonadTrans (EventWriterT t w) where
121− lift = EventWriterT . lift
122−
123131instance MonadSample t m => MonadSample t (EventWriterT t w m) where
124132 sample = lift . sample
125133
src/Reflex/Query/Base.hs+4
@@ -22,6 +22,7 @@ module Reflex.Query.Base
2222import Control.Applicative (liftA2)
2323import Control.Monad.Exception
2424import Control.Monad.Fix
25+import Control.Monad.Morph
2526import Control.Monad.Primitive
2627import Control.Monad.Reader
2728import Control.Monad.Ref
@@ -239,6 +240,9 @@ instance (Reflex t, MonadFix m, Group q, Additive q, Query q, Eq q, MonadHold t
239240instance MonadTrans (QueryT t q) where
240241 lift = QueryT . lift . lift . lift
241242
243+instance MFunctor (QueryT t q) where
244+ hoist = mapQueryT
245+
242246instance PrimMonad m => PrimMonad (QueryT t q m) where
243247 type PrimState (QueryT t q m) = PrimState m
244248 primitive = lift . primitive
src/Reflex/Requester/Base.hs+4
@@ -49,6 +49,7 @@ import Reflex.TriggerEvent.Class
4949import Control.Applicative (liftA2)
5050import Control.Monad.Exception
5151import Control.Monad.Identity
52+import Control.Monad.Morph
5253import Control.Monad.Primitive
5354import Control.Monad.Reader
5455import Control.Monad.Ref
@@ -317,6 +318,9 @@ responseFromTag (MyTagWrap t) = do
317318instance MonadTrans (RequesterT t request response) where
318319 lift = RequesterT . lift . lift
319320
321+instance MFunctor (RequesterT t request response) where
322+ hoist f = RequesterT . hoist (hoist f) . unRequesterT
323+
320324instance PerformEvent t m => PerformEvent t (RequesterT t request response m) where
321325 type Performable (RequesterT t request response m) = Performable m
322326 performEvent_ = lift . performEvent_