Add note about instance deriving to Monad{Conc,STM} docs

This commit is contained in:
Michael Walker 2018-01-19 16:45:38 +00:00
parent d62f0c24d8
commit 7a13b106d9
2 changed files with 47 additions and 0 deletions

View File

@ -122,6 +122,30 @@ import qualified Control.Monad.Writer.Strict as WS
-- Every @MonadConc@ has an associated 'MonadSTM', transactions of
-- which can be run atomically.
--
-- __Deriving instances:__ If you have a newtype wrapper around a type
-- with an existing @MonadConc@ instance, you should be able to derive
-- an instance for your type automatically, in simple cases.
--
-- For example:
--
-- > {-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- > {-# LANGUAGE StandaloneDeriving #-}
-- > {-# LANGUAGE UndecidableInstances #-}
-- >
-- > data Env = Env
-- >
-- > newtype MyMonad m a = MyMonad { runMyMonad :: ReaderT Env m a }
-- > deriving (Functor, Applicative, Monad)
-- >
-- > deriving instance MonadThrow m => MonadThrow (MyMonad m)
-- > deriving instance MonadCatch m => MonadCatch (MyMonad m)
-- > deriving instance MonadMask m => MonadMask (MyMonad m)
-- >
-- > deriving instance MonadConc m => MonadConc (MyMonad m)
--
-- Do not be put off by the use of @UndecidableInstances@, it is safe
-- here.
--
-- @since unreleased
class ( Applicative m, Monad m
, MonadCatch m, MonadThrow m, MonadMask m

View File

@ -18,6 +18,29 @@
-- import "Control.Concurrent.Classy.STM" (which exports
-- "Control.Monad.STM.Class").
--
-- __Deriving instances:__ If you have a newtype wrapper around a type
-- with an existing @MonadSTM@ instance, you should be able to derive
-- an instance for your type automatically, in simple cases.
--
-- For example:
--
-- > {-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- > {-# LANGUAGE StandaloneDeriving #-}
-- > {-# LANGUAGE UndecidableInstances #-}
-- >
-- > data Env = Env
-- >
-- > newtype MyMonad m a = MyMonad { runMyMonad :: ReaderT Env m a }
-- > deriving (Functor, Applicative, Monad, Alternative, MonadPlus)
-- >
-- > deriving instance MonadThrow m => MonadThrow (MyMonad m)
-- > deriving instance MonadCatch m => MonadCatch (MyMonad m)
-- >
-- > deriving instance MonadSTM m => MonadSTM (MyMonad m)
--
-- Do not be put off by the use of @UndecidableInstances@, it is safe
-- here.
--
-- __Deviations:__ An instance of @MonadSTM@ is not required to be a
-- @MonadFix@, unlike @STM@. The @always@ and @alwaysSucceeds@
-- functions are not provided; if you need these file an issue and