Skip to content

Commit

Permalink
Add MonadMask, MonadCatch, MonadThrow instances
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-abrar committed Jul 7, 2023
1 parent 2e726a2 commit d77ad8c
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 11 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
@@ -1,5 +1,9 @@
# Revision history for reflex

## Unreleased

* Add MonadMask, MonadCatch, MonadThrow instances

## 0.9.1.0

* Headless Host: Add some MonadSample, MonadHold, and MonadFix instances
Expand Down
1 change: 1 addition & 0 deletions reflex.cabal
Expand Up @@ -80,6 +80,7 @@ library
containers >= 0.6 && < 0.7,
data-default >= 0.5 && < 0.8,
dependent-map >= 0.3 && < 0.5,
exceptions >= 0.10 && < 0.11,
exception-transformers >= 0.4 && < 0.5,
lens >= 4.7 && < 5.3,
mmorph >= 1.0 && < 1.3,
Expand Down
4 changes: 4 additions & 0 deletions src/Reflex/BehaviorWriter/Base.hs
Expand Up @@ -22,6 +22,7 @@ module Reflex.BehaviorWriter.Base
) where

import Control.Monad
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity
Expand Down Expand Up @@ -62,6 +63,9 @@ newtype BehaviorWriterT t w m a = BehaviorWriterT { unBehaviorWriterT :: StateT
, MonadFix
, MonadAsyncException
, MonadException
, MonadCatch
, MonadThrow
, MonadMask
)

-- | Run a 'BehaviorWriterT' action. The behavior writer output will be provided
Expand Down
4 changes: 4 additions & 0 deletions src/Reflex/DynamicWriter/Base.hs
Expand Up @@ -20,6 +20,7 @@ module Reflex.DynamicWriter.Base
) where

import Control.Monad
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity
Expand Down Expand Up @@ -101,6 +102,9 @@ newtype DynamicWriterT t w m a = DynamicWriterT { unDynamicWriterT :: StateT [Dy
, MonadFix
, MonadAsyncException
, MonadException
, MonadCatch
, MonadThrow
, MonadMask
)

deriving instance MonadHold t m => MonadHold t (DynamicWriterT t w m)
Expand Down
4 changes: 4 additions & 0 deletions src/Reflex/EventWriter/Base.hs
Expand Up @@ -33,6 +33,7 @@ import Reflex.Query.Class
import Reflex.Requester.Class
import Reflex.TriggerEvent.Class

import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity
Expand Down Expand Up @@ -109,6 +110,9 @@ newtype EventWriterT t w m a = EventWriterT { unEventWriterT :: StateT (EventWri
, MonadIO
, MonadException
, MonadAsyncException
, MonadMask
, MonadCatch
, MonadThrow
)

-- | Run a 'EventWriterT' action.
Expand Down
16 changes: 10 additions & 6 deletions src/Reflex/Host/Headless.hs
Expand Up @@ -8,6 +8,7 @@ module Reflex.Host.Headless where

import Control.Concurrent.Chan (newChan, readChan)
import Control.Monad (unless)
import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow)
import Control.Monad.Fix (MonadFix, fix)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Primitive (PrimMonad)
Expand All @@ -23,26 +24,29 @@ import Reflex
import Reflex.Host.Class

type MonadHeadlessApp t m =
( Adjustable t m
( Reflex t
, Adjustable t m
, MonadCatch m
, MonadFix (Performable m)
, MonadFix m
, MonadHold t (Performable m)
, MonadHold t m
, MonadIO (HostFrame t)
, MonadIO (Performable m)
, MonadIO m
, MonadMask m
, MonadRef (HostFrame t)
, MonadSample t (Performable m)
, MonadSample t m
, MonadThrow m
, NotReady t m
, PerformEvent t m
, PostBuild t m
, PrimMonad (HostFrame t)
, Ref (HostFrame t) ~ IORef
, Ref m ~ IORef
, Reflex t
, ReflexHost t
, TriggerEvent t m
, MonadSample t (Performable m)
, MonadSample t m
, MonadFix (Performable m)
, MonadHold t (Performable m)
)

-- | Run a headless FRP network. Inside the action, you will most probably use
Expand Down
4 changes: 4 additions & 0 deletions src/Reflex/PerformEvent/Base.hs
Expand Up @@ -32,6 +32,7 @@ import Reflex.Requester.Base
import Reflex.Requester.Class

import Control.Lens
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity
Expand Down Expand Up @@ -64,6 +65,9 @@ deriving instance (ReflexHost t, MonadIO (HostFrame t)) => MonadIO (PerformEvent
deriving instance (ReflexHost t, MonadException (HostFrame t)) => MonadException (PerformEventT t m)
deriving instance (ReflexHost t, Monoid a) => Monoid (PerformEventT t m a)
deriving instance (ReflexHost t, S.Semigroup a) => S.Semigroup (PerformEventT t m a)
deriving instance (ReflexHost t, MonadCatch (HostFrame t)) => MonadCatch (PerformEventT t m)
deriving instance (ReflexHost t, MonadThrow (HostFrame t)) => MonadThrow (PerformEventT t m)
deriving instance (ReflexHost t, MonadMask (HostFrame t)) => MonadMask (PerformEventT t m)

instance (PrimMonad (HostFrame t), ReflexHost t) => PrimMonad (PerformEventT t m) where
type PrimState (PerformEventT t m) = PrimState (HostFrame t)
Expand Down
16 changes: 15 additions & 1 deletion src/Reflex/PostBuild/Base.hs
Expand Up @@ -29,6 +29,7 @@ import Reflex.PostBuild.Class
import Reflex.TriggerEvent.Class

import Control.Applicative (liftA2)
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity
Expand All @@ -44,7 +45,20 @@ import qualified Data.IntMap.Strict as IntMap
import qualified Data.Semigroup as S

-- | Provides a basic implementation of 'PostBuild'.
newtype PostBuildT t m a = PostBuildT { unPostBuildT :: ReaderT (Event t ()) m a } deriving (Functor, Applicative, Monad, MonadFix, MonadIO, MonadTrans, MonadException, MonadAsyncException)
newtype PostBuildT t m a = PostBuildT { unPostBuildT :: ReaderT (Event t ()) m a }
deriving
( Functor
, Applicative
, Monad
, MonadFix
, MonadIO
, MonadTrans
, MonadException
, MonadAsyncException
, MonadMask
, MonadThrow
, MonadCatch
)

-- | Run a 'PostBuildT' action. An 'Event' should be provided that fires
-- immediately after the action is finished running; no other 'Event's should
Expand Down
3 changes: 2 additions & 1 deletion src/Reflex/Query/Base.hs
Expand Up @@ -20,6 +20,7 @@ module Reflex.Query.Base
) where

import Control.Applicative (liftA2)
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Morph
Expand Down Expand Up @@ -60,7 +61,7 @@ import Reflex.Requester.Class
import Reflex.TriggerEvent.Class

newtype QueryT t q m a = QueryT { unQueryT :: StateT [Behavior t q] (EventWriterT t q (ReaderT (Dynamic t (QueryResult q)) m)) a }
deriving (Functor, Applicative, Monad, MonadException, MonadFix, MonadIO, MonadAtomicRef)
deriving (Functor, Applicative, Monad, MonadException, MonadFix, MonadIO, MonadAtomicRef, MonadCatch, MonadThrow, MonadMask)

deriving instance MonadHold t m => MonadHold t (QueryT t q m)
deriving instance MonadSample t m => MonadSample t (QueryT t q m)
Expand Down
4 changes: 4 additions & 0 deletions src/Reflex/Requester/Base/Internal.hs
Expand Up @@ -33,6 +33,7 @@ import Reflex.TriggerEvent.Class

import Control.Applicative (liftA2)
import Control.Monad
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity
Expand Down Expand Up @@ -277,6 +278,9 @@ newtype RequesterT t request (response :: Type -> Type) m a = RequesterT { unReq
#if MIN_VERSION_base(4,9,1)
, MonadAsyncException
#endif
, MonadCatch
, MonadThrow
, MonadMask
)

deriving instance MonadSample t m => MonadSample t (RequesterT t request response m)
Expand Down
6 changes: 4 additions & 2 deletions src/Reflex/Spider/Internal.hs
Expand Up @@ -35,6 +35,7 @@ import Control.Applicative (liftA2)
import Control.Concurrent
import Control.Exception
import Control.Monad hiding (forM, forM_, mapM, mapM_)
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Identity hiding (forM, forM_, mapM, mapM_)
Expand Down Expand Up @@ -1058,7 +1059,8 @@ data SomeMergeUpdate x = SomeMergeUpdate
newtype SomeMergeInit x = SomeMergeInit { unSomeMergeInit :: EventM x () }

-- EventM can do everything BehaviorM can, plus create holds
newtype EventM x a = EventM { unEventM :: IO a } deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadException, MonadAsyncException)
newtype EventM x a = EventM { unEventM :: IO a }
deriving (Functor, Applicative, Monad, MonadIO, MonadFix, MonadException, MonadAsyncException, MonadCatch, MonadThrow, MonadMask)

newtype MergeSubscribedParent x a = MergeSubscribedParent { unMergeSubscribedParent :: EventSubscription x }

Expand Down Expand Up @@ -2864,7 +2866,7 @@ runSpiderHostForTimeline :: SpiderHost x a -> SpiderTimelineEnv x -> IO a
runSpiderHostForTimeline (SpiderHost a) _ = a

newtype SpiderHostFrame (x :: Type) a = SpiderHostFrame { runSpiderHostFrame :: EventM x a }
deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException)
deriving (Functor, Applicative, MonadFix, MonadIO, MonadException, MonadAsyncException, MonadMask, MonadThrow, MonadCatch)

instance Monad (SpiderHostFrame x) where
{-# INLINABLE (>>=) #-}
Expand Down
3 changes: 2 additions & 1 deletion src/Reflex/TriggerEvent/Base.hs
Expand Up @@ -15,6 +15,7 @@ module Reflex.TriggerEvent.Base

import Control.Applicative (liftA2)
import Control.Concurrent
import Control.Monad.Catch (MonadMask, MonadThrow, MonadCatch)
import Control.Monad.Exception
import Control.Monad.Fix
import Control.Monad.Primitive
Expand All @@ -41,7 +42,7 @@ newtype EventTriggerRef t a = EventTriggerRef { unEventTriggerRef :: IORef (Mayb

-- | A basic implementation of 'TriggerEvent'.
newtype TriggerEventT t m a = TriggerEventT { unTriggerEventT :: ReaderT (Chan [DSum (EventTriggerRef t) TriggerInvocation]) m a }
deriving (Functor, Applicative, Monad, MonadFix, MonadIO, MonadException, MonadAsyncException)
deriving (Functor, Applicative, Monad, MonadFix, MonadIO, MonadException, MonadAsyncException, MonadCatch, MonadThrow, MonadMask)

-- | Run a 'TriggerEventT' action. The argument should be a 'Chan' into which
-- 'TriggerInvocation's can be passed; it is expected that some other thread
Expand Down

0 comments on commit d77ad8c

Please sign in to comment.