monoids 0.1.8 → 0.1.9
raw patch · 3 files changed
+45/−1 lines, 3 files
Files
- Data/Monoid/Generator/RLE.hs +1/−0
- Data/Monoid/Self.hs +42/−0
- monoids.cabal +2/−1
Data/Monoid/Generator/RLE.hs view
@@ -18,6 +18,7 @@ module Data.Monoid.Generator.RLE ( module Data.Monoid.Generator , RLE(RLE, getRLE)+ , Run(Run) , decode , encode , encodeList
+ Data/Monoid/Self.hs view
@@ -0,0 +1,42 @@+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, GeneralizedNewtypeDeriving #-}++-----------------------------------------------------------------------------+-- |+-- Module : Data.Monoid.Self+-- Copyright : (c) Edward Kmett 2009+-- License : BSD-style+-- Maintainer : libraries@haskell.org+-- Stability : experimental+-- Portability : portable+--+-- A simple 'Monoid' transformer that takes a 'Monoid' m and produces a new @m@-Reducer named 'Self' @m@+-- +-- This is useful when you have a generator that already contains monoidal values or someone supplies+-- the map to the monoid in the form of a function rather than as a "Reducer" instance. You can just+-- @'getSelf' . `reduce`@ or @'getSelf' . 'mapReduce' f@ in those scenarios. These behaviors are encapsulated +-- into the 'fold' and 'foldMap' combinators in "Data.Monoid.Combinators" respectively.+--+-----------------------------------------------------------------------------++module Data.Monoid.Self+ ( module Data.Monoid.Reducer+ , Self(Self, getSelf)+ ) where++import Control.Functor.Pointed+import Data.Monoid.Reducer+import Data.Monoid.Generator++newtype Self m = Self { getSelf :: m } deriving (Monoid)++instance Monoid m => Reducer m (Self m) where+ unit = Self++instance Functor Self where+ fmap f (Self x) = Self (f x)++instance Pointed Self where+ point = Self++instance Copointed Self where+ extract = getSelf
monoids.cabal view
@@ -1,5 +1,5 @@ name: monoids-version: 0.1.8+version: 0.1.9 license: BSD3 license-file: LICENSE author: Edward A. Kmett@@ -48,6 +48,7 @@ Data.Monoid.Multiplicative Data.Monoid.Multiplicative.Sugar Data.Monoid.Ord+ Data.Monoid.Self Data.Monoid.Reducer Data.Monoid.Reducer.Char Data.Monoid.Reducer.With