packages feed

monad-supply 0.2 → 0.3

raw patch · 2 files changed

+18/−6 lines, 2 files

Files

monad-supply.cabal view
@@ -1,6 +1,6 @@ Name:          monad-supply Build-type:    Simple-Version:       0.2+Version:       0.3 Cabal-Version: >= 1.6 Synopsis:      Stateful supply monad. Description:   Support for computations which consume values from a (possibly infinite) supply.
src/Control/Monad/Supply.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE MultiParamTypeClasses #-}  -- | Support for computations which consume values from a (possibly infinite)--- supply. See http://www.haskell.org/haskellwiki/New_monads/MonadSupply for+-- supply. See <http://www.haskell.org/haskellwiki/New_monads/MonadSupply> for -- details. module Control.Monad.Supply ( MonadSupply (..)@@ -23,10 +23,11 @@ import Control.Monad.Error import Control.Monad.Reader import Control.Monad.Writer-import Data.Monoid  class Monad m => MonadSupply s m | m -> s where   supply :: m s+  peek :: m s+  exhausted :: m Bool  -- | Supply monad transformer. newtype SupplyT s m a = SupplyT (StateT [s] m a)@@ -40,23 +41,34 @@   supply = SupplyT $ do (x:xs) <- get                         put xs                         return x+  peek = SupplyT $ gets head+  exhausted = SupplyT $ gets null  -- Monad transformer instances instance (Error e,MonadSupply s m) => MonadSupply s (ErrorT e m) where   supply = lift supply+  peek = lift peek+  exhausted = lift exhausted  instance MonadSupply s m => MonadSupply s (StateT st m) where   supply = lift supply+  peek = lift peek+  exhausted = lift exhausted  instance MonadSupply s m => MonadSupply s (ReaderT r m) where   supply = lift supply+  peek = lift peek+  exhausted = lift exhausted  instance (Monoid w, MonadSupply s m) => MonadSupply s (WriterT w m) where   supply = lift supply+  peek = lift peek+  exhausted = lift exhausted --- | Monoid instance for the supply monad. Actually any monad/monoid pair gives--- rise to this monoid instance, but we can't write it like that because it--- would conflict with existing instances provided by Data.Monoid.+-- | Monoid instance for the supply monad. Actually any monad/monoid pair+-- gives rise to this monoid instance, but we can't write its type like that+-- because it would conflict with existing instances provided by Data.Monoid.+--instance (Monoid a, Monad m) => Monoid (m a) where instance (Monoid a) => Monoid (Supply s a) where   mempty = return mempty   m1 `mappend` m2 = do