monoid-transformer (empty) → 0.0.1
raw patch · 6 files changed
+123/−0 lines, 6 filesdep +basesetup-changed
Dependencies added: base
Files
- LICENSE +31/−0
- Setup.lhs +3/−0
- monoid-transformer.cabal +37/−0
- src/Data/Monoid/Reader.hs +15/−0
- src/Data/Monoid/State.hs +31/−0
- src/Data/Monoid/Transformer.hs +6/−0
+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (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.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#! /usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ monoid-transformer.cabal view
@@ -0,0 +1,37 @@+Name: monoid-transformer+Version: 0.0.1+License: BSD3+License-File: LICENSE+Author: Henning Thielemann <haskell@henning-thielemann.de>+Maintainer: Henning Thielemann <haskell@henning-thielemann.de>+-- 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.1+++Library+ Build-Depends: base++ GHC-Options: -Wall+ Hs-Source-Dirs: src+ Exposed-Modules:+ Data.Monoid.Reader+ Data.Monoid.State+ Data.Monoid.Transformer
+ src/Data/Monoid/Reader.hs view
@@ -0,0 +1,15 @@+module 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}++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
+ src/Data/Monoid/State.hs view
@@ -0,0 +1,31 @@+module Data.Monoid.State where++import qualified Data.Monoid.Transformer as MonoidTrans+import Data.Monoid (Monoid, mempty, mappend, )++newtype T s a = Cons {run :: 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 r) where+ lift x = Cons $ (,) x
+ src/Data/Monoid/Transformer.hs view
@@ -0,0 +1,6 @@+module Data.Monoid.Transformer where++import Data.Monoid (Monoid, )++class C t where+ lift :: (Monoid m) => m -> t m