packages feed

acme-all-monad (empty) → 0.1.0.0

raw patch · 5 files changed

+170/−0 lines, 5 filesdep +basedep +transformerssetup-changed

Dependencies added: base, transformers

Files

+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ acme-all-monad.cabal view
@@ -0,0 +1,19 @@+name:                acme-all-monad+version:             0.1.0.0+synopsis:            A monad which is powerful enough to interpret any action+license:             PublicDomain+author:              Phil Freeman+maintainer:          paf31@cantab.net+category:            Acme+build-type:          Simple+cabal-version:       >=1.10+description:+    This package defines the @‘All’@ monad and the corresponding monad transformer. The @‘All’@ monad is powerful enough to interpret any monadic action, as demonstrated by the @‘MonadAll’@ type class instance.++library+  exposed-modules:     Control.Monad.All+                       Control.Monad.All.Trans+                       Control.Monad.All.Class +  build-depends:       base >=4.7 && <4.8, transformers >= 0.4.0.0 && < 0.5.0.0+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Control/Monad/All.hs view
@@ -0,0 +1,19 @@+-- |+-- Module    :  Control.Monad.All+-- License   :  Public Domain+-- Stability :  stable+--+-- The @All@ monad, which is powerful enough to interpret any monadic action.++module Control.Monad.All where++import Data.Functor.Identity+import Control.Monad.All.Trans++-- | The @All@ monad.+-- +-- @All@ is powerful enough to interpret any monadic action, which makes it very convenient for+-- defining domain specific languages.+--+-- @All@ is defined as a type synonym for @'AllT' 'Identity'@.+type All = AllT Identity
+ src/Control/Monad/All/Class.hs view
@@ -0,0 +1,78 @@+-- |+-- Module    :  Control.Monad.All.Class+-- License   :  Public Domain+-- Stability :  stable+--+-- The @MonadAll@ type class, which represents monads which are powerful enough to interpret any monadic action.++module Control.Monad.All.Class where++import Data.Monoid++import Control.Monad.All.Trans++import Control.Monad.Trans.Class++import Control.Monad.Trans.Identity+import Control.Monad.Trans.Except+import Control.Monad.Trans.List+import Control.Monad.Trans.Maybe+import Control.Monad.Trans.Reader++import qualified Control.Monad.Trans.State.Lazy as SL+import qualified Control.Monad.Trans.State.Strict as SS++import Control.Monad.Trans.Writer.Lazy as WL+import Control.Monad.Trans.Writer.Strict as WS++import qualified Control.Monad.Trans.RWS.Lazy as RWSL+import qualified Control.Monad.Trans.RWS.Strict as RWSS++-- | The @MonadAll@ class represents those monads which support every monadic action.+--  +-- Instances are provided for @AllT@ and the standard monad transformers, so that you can use+-- arbitrary actions in other monad transformer stacks.+class (Monad m) => MonadAll m where+  action :: a -> m b+  +-- | Perform an action, discarding the result.+action_ :: (MonadAll m) => a -> m ()+action_ a = do+  _ <- action a+  return ()++instance MonadAll (AllT m) where+  action _ = anything++instance (MonadAll m) => MonadAll (IdentityT m) where+  action = lift . action++instance (MonadAll m) => MonadAll (ExceptT e m) where+  action = lift . action++instance (MonadAll m) => MonadAll (ListT m) where+  action = lift . action++instance (MonadAll m) => MonadAll (MaybeT m) where+  action = lift . action++instance (MonadAll m) => MonadAll (ReaderT r m) where+  action = lift . action++instance (MonadAll m, Monoid w) => MonadAll (WL.WriterT w m) where+  action = lift . action++instance (MonadAll m, Monoid w) => MonadAll (WS.WriterT w m) where+  action = lift . action++instance (MonadAll m) => MonadAll (SL.StateT s m) where+  action = lift . action++instance (MonadAll m) => MonadAll (SS.StateT s m) where+  action = lift . action++instance (MonadAll m, Monoid w) => MonadAll (RWSL.RWST r w s m) where+  action = lift . action++instance (MonadAll m, Monoid w) => MonadAll (RWSS.RWST r w s m) where+  action = lift . action
+ src/Control/Monad/All/Trans.hs view
@@ -0,0 +1,52 @@+-- |+-- Module    :  Control.Monad.All.Trans+-- License   :  Public Domain+-- Stability :  stable+--+-- The @AllT@ monad monad transformer.++{-# LANGUAGE KindSignatures #-}++module Control.Monad.All.Trans (AllT(), anything) where++import Control.Monad+import Control.Monad.IO.Class+import Control.Monad.Trans.Class+import Control.Applicative++-- | The @AllT@ monad transformer.+-- +-- @AllT@ is powerful enough to interpret any monadic action, which makes it very convenient for+-- defining domain specific languages.+--+-- Of course, any actions supported by the base monad are also supported by @AllT@.+data AllT (m :: * -> *) a = AllT++-- | Create any value in the @AllT@ monad.+anything :: AllT m a+anything = AllT++instance Functor (AllT m) where+  fmap f _ = AllT++instance Applicative (AllT m) where+  pure _ = AllT+  _ <*> _ = AllT++instance Monad (AllT m) where+  return _ = AllT+  _ >>= _ = AllT++instance Alternative (AllT m) where+  empty = AllT+  _ <|> _ = AllT++instance MonadPlus (AllT m) where+  mzero = AllT+  mplus _ _ = AllT++instance MonadTrans AllT where+  lift _ = AllT++instance MonadIO (AllT m) where+  liftIO _ = AllT