packages feed

monoid-transformer 0.0.1 → 0.0.2

raw patch · 3 files changed

+32/−4 lines, 3 filesdep ~base

Dependency ranges changed: base

Files

monoid-transformer.cabal view
@@ -1,5 +1,5 @@ Name:             monoid-transformer-Version:          0.0.1+Version:          0.0.2 License:          BSD3 License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>@@ -10,6 +10,7 @@ -- 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@@ -23,11 +24,11 @@ Source-Repository this   type:     darcs   location: http://code.haskell.org/~thielema/monoid/-  tag:      0.0.1+  tag:      0.0.2   Library-  Build-Depends: base+  Build-Depends: base >= 1 && <5    GHC-Options:      -Wall   Hs-Source-Dirs:   src
src/Data/Monoid/Reader.hs view
@@ -6,6 +6,9 @@  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) =@@ -13,3 +16,6 @@  instance MonoidTrans.C (T r) where    lift = Cons . const++instance Functor (T r) where+   fmap f (Cons g) = Cons (f . g)
src/Data/Monoid/State.hs view
@@ -3,8 +3,21 @@ 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 @@ -27,5 +40,13 @@              (yr,s2) = y s1          in  (mappend xr yr, s2) -instance MonoidTrans.C (T r) where+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)