monoid-transformer-0.0.2/0000755000000000000000000000000011246326546013535 5ustar0000000000000000monoid-transformer-0.0.2/monoid-transformer.cabal0000644000000000000000000000207711246326546020354 0ustar0000000000000000Name: monoid-transformer Version: 0.0.2 License: BSD3 License-File: LICENSE Author: Henning Thielemann Maintainer: Henning Thielemann -- Homepage: http://www.haskell.org/haskellwiki/Monoid transformer Category: Data Synopsis: Monoid counterparts to some ubiquitous monad transformers -- Portability: Haskell 98 Description: Monoid transformers: State, Reader . There is no Writer transformer. It's vice versa: The Writer monad transforms a monoid to a monad. Tested-With: GHC==6.8.2 Cabal-Version: >=1.6 Build-Type: Simple Source-Repository head type: darcs location: http://code.haskell.org/~thielema/monoid/ Source-Repository this type: darcs location: http://code.haskell.org/~thielema/monoid/ tag: 0.0.2 Library Build-Depends: base >= 1 && <5 GHC-Options: -Wall Hs-Source-Dirs: src Exposed-Modules: Data.Monoid.Reader Data.Monoid.State Data.Monoid.Transformer monoid-transformer-0.0.2/Setup.lhs0000755000000000000000000000011511246326546015345 0ustar0000000000000000#! /usr/bin/env runhaskell > import Distribution.Simple > main = defaultMain monoid-transformer-0.0.2/LICENSE0000644000000000000000000000272111246326546014544 0ustar0000000000000000Copyright (c) 2009, Henning Thielemann All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The names of contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. monoid-transformer-0.0.2/src/0000755000000000000000000000000011246326546014324 5ustar0000000000000000monoid-transformer-0.0.2/src/Data/0000755000000000000000000000000011246326546015175 5ustar0000000000000000monoid-transformer-0.0.2/src/Data/Monoid/0000755000000000000000000000000011246326546016422 5ustar0000000000000000monoid-transformer-0.0.2/src/Data/Monoid/Reader.hs0000644000000000000000000000074711246326546020170 0ustar0000000000000000module Data.Monoid.Reader where import qualified Data.Monoid.Transformer as MonoidTrans import Data.Monoid (Monoid, mempty, mappend, ) newtype T r a = Cons {run :: r -> a} pure :: a -> T r a pure = Cons . const instance Monoid a => Monoid (T r a) where mempty = MonoidTrans.lift mempty mappend (Cons x) (Cons y) = Cons $ \r -> mappend (x r) (y r) instance MonoidTrans.C (T r) where lift = Cons . const instance Functor (T r) where fmap f (Cons g) = Cons (f . g) monoid-transformer-0.0.2/src/Data/Monoid/State.hs0000644000000000000000000000230511246326546020036 0ustar0000000000000000module Data.Monoid.State where import qualified Data.Monoid.Transformer as MonoidTrans import Data.Monoid (Monoid, mempty, mappend, ) {- | This resembles the pure State monad. However, State in transformers is a StateT and mtl is not Haskell 98. I hope I have the more natural parameter order for 'evaluate' in contrast to @mtl@ and @transformers@. However, it is different from the parameter order of 'run'. -} newtype T s a = Cons {run :: s -> (a,s)} pure :: a -> T s a pure a = Cons $ \s -> (a,s) evaluate :: s -> T s a -> a evaluate s m = fst $ run m s execute :: s -> T s a -> s execute s m = snd $ run m s put :: Monoid a => s -> T s a put s = Cons $ const (mempty, s) modify :: Monoid a => (s -> s) -> T s a modify f = Cons $ \s -> (mempty, f s) instance Monoid a => Monoid (T s a) where mempty = MonoidTrans.lift mempty mappend (Cons x) (Cons y) = Cons $ \s0 -> let (xr,s1) = x s0 (yr,s2) = y s1 in (mappend xr yr, s2) instance MonoidTrans.C (T s) where lift x = Cons $ (,) x instance Functor (T s) where fmap f (Cons g) = Cons (mapFst f . g) -- from utility-ht {-# INLINE mapFst #-} mapFst :: (a -> c) -> (a,b) -> (c,b) mapFst f ~(a,b) = (f a, b) monoid-transformer-0.0.2/src/Data/Monoid/Transformer.hs0000644000000000000000000000016711246326546021264 0ustar0000000000000000module Data.Monoid.Transformer where import Data.Monoid (Monoid, ) class C t where lift :: (Monoid m) => m -> t m