[added Data.Sequence ekmett@gmail.com**20090327040022] { hunk ./Data/Monoid/Generator.hs 20 +import Data.Sequence (Seq) +import Data.FingerTree (Measured, FingerTree) hunk ./Data/Monoid/Generator.hs 49 + +instance Measured v m => Generator (FingerTree v m) where + type Elem (FingerTree v m) = m + mapReduce f = foldMap (unit . f) + +instance Generator (Seq c) where + type Elem (Seq c) = c + mapReduce f = foldMap (unit . f) hunk ./Data/Monoid/Multiplicative.hs 5 + , Seminearring hunk ./Data/Monoid/Multiplicative.hs 14 +import qualified Data.Sequence as Seq +import Data.Sequence (Seq) hunk ./Data/Monoid/Multiplicative.hs 31 - xss `times` yss = getSelf . reduce . fmap (\xs -> fmap' (xs `mappend`) yss) $ toList xss + xss `times` yss = getSelf $ mapReduce (flip fmap' yss . mappend) xss + +instance (Monoid m) => MultiplicativeMonoid (Seq m) where + one = Seq.singleton mempty + xss `times` yss = getSelf $ mapReduce (flip fmap yss . mappend) xss hunk ./Data/Monoid/Multiplicative.hs 47 +-- class Absorbing m where isZero :: m -> Bool + hunk ./Data/Monoid/Reducer.hs 14 +import qualified Data.Sequence as Seq +import Data.Sequence (Seq) hunk ./Data/Monoid/Reducer.hs 88 +-- orphan, which should be in Data.FingerTree hunk ./Data/Monoid/Reducer.hs 98 +instance Reducer a (Seq a) where + unit = Seq.singleton + cons = (Seq.<|) + snoc = (Seq.|>) + hunk ./Data/Monoid/Self.hs 8 -import Data.Foldable hunk ./Data/Monoid/Self.hs 10 -import GHC.Exts hunk ./dist/doc/html/monoids/Data-Monoid-Generator.html 268 +>Generator (Seq c)Measured v m => Generator (FingerTree v m)Monoid m => MultiplicativeMonoid (Seq m)
class (MultiplicativeMonoid m, Monoid m) => Seminearring m Source
Reducer a (Seq a) --- minimal definition mapReduce or affixMapReduce -classGeneratorcwhere -typeElemc::* -mapReduce::(e`Reducer`m)=>(Elemc->e)->c->m -mapTo::(e`Reducer`m)=>(Elemc->e)->m->c->m -mapFrom::(e`Reducer`m)=>(Elemc->e)->c->m->m - -mapReducef=mapTofmempty -mapTofm=mappendm.mapReducef -mapFromf=mappend.mapReducef - -instanceGeneratorStrict.ByteStringwhere -typeElemStrict.ByteString=Word8 -mapTof=Strict.foldl'(\a->snoca.f) - -instanceGeneratorLazy.ByteStringwhere -typeElemLazy.ByteString=ElemStrict.ByteString -mapReducef=fold.parMaprwhnf(mapReducef).Lazy.toChunks - -instanceGeneratorTextwhere -typeElemText=Char -mapTof=Text.foldl'(\a->snoca.f) - -instanceGenerator[c]where -typeElem[c]=c -mapReducef=foldMap(unit.f) - -{-# SPECIALIZE reduce :: (Word8 `Reducer` m) => Strict.ByteString -> m #-} -{-# SPECIALIZE reduce :: (Word8 `Reducer` m) => Lazy.ByteString -> m #-} -{-# SPECIALIZE reduce :: (Char `Reducer` m) => Text -> m #-} --- These aren't happy, but should work -{-- RULES "reduce/fold" reduce = fold --} -{-- RULES "mapReduce/foldMap" mapReduce = foldMap --} -reduce::(Generatorc,Elemc`Reducer`m)=>c->m -reduce=mapReduceid +importData.Sequence(Seq) +importData.FingerTree(Measured,FingerTree) + +-- minimal definition mapReduce or affixMapReduce +classGeneratorcwhere +typeElemc::* +mapReduce::(e`Reducer`m)=>(Elemc->e)->c->m +mapTo::(e`Reducer`m)=>(Elemc->e)->m->c->m +mapFrom::(e`Reducer`m)=>(Elemc->e)->c->m->m + +mapReducef=mapTofmempty +mapTofm=mappendm.mapReducef +mapFromf=mappend.mapReducef + +instanceGeneratorStrict.ByteStringwhere +typeElemStrict.ByteString=Word8 +mapTof=Strict.foldl'(\a->snoca.f) + +instanceGeneratorLazy.ByteStringwhere +typeElemLazy.ByteString=ElemStrict.ByteString +mapReducef=fold.parMaprwhnf(mapReducef).Lazy.toChunks + +instanceGeneratorTextwhere +typeElemText=Char +mapTof=Text.foldl'(\a->snoca.f) + +instanceGenerator[c]where +typeElem[c]=c +mapReducef=foldMap(unit.f) + +instanceMeasuredvm=>Generator(FingerTreevm)where +typeElem(FingerTreevm)=m +mapReducef=foldMap(unit.f) + +instanceGenerator(Seqc)where +typeElem(Seqc)=c +mapReducef=foldMap(unit.f) + +{-# SPECIALIZE reduce :: (Word8 `Reducer` m) => Strict.ByteString -> m #-} +{-# SPECIALIZE reduce :: (Word8 `Reducer` m) => Lazy.ByteString -> m #-} +{-# SPECIALIZE reduce :: (Char `Reducer` m) => Text -> m #-} +-- These aren't happy, but should work +{-- RULES "reduce/fold" reduce = fold --} +{-- RULES "mapReduce/foldMap" mapReduce = foldMap --} +reduce::(Generatorc,Elemc`Reducer`m)=>c->m +reduce=mapReduceid hunk ./dist/doc/html/monoids/src/Data-Monoid-Multiplicative.html 13 -)where - -importData.Monoid.Additive -importData.FingerTree -importData.Monoid.Self -importData.Monoid.FromString -importData.Monoid.Generator -importData.Foldable - -classMultiplicativeMonoidmwhere -one::m -times::m->m->m - -class(MultiplicativeMonoidm,Monoidm)=>Seminearringm - -instanceMonoidm=>MultiplicativeMonoid[m]where -one=[mempty] -xss`times`yss=[xs`mappend`ys|xs<-xss,ys<-yss] - -instanceMonoidm=>Seminearring[m] - -instance(Measuredvm,Monoidm)=>MultiplicativeMonoid(FingerTreevm)where -one=singletonmempty -xss`times`yss=getSelf.reduce.fmap(\xs->fmap'(xs`mappend`)yss)$toListxss - -instance(Measuredvm,Monoidm)=>Seminearring(FingerTreevm) - -instanceMultiplicativeMonoidm=>MultiplicativeMonoid(Selfm)where -one=Selfone -Selfa`times`Selfb=Self(a`times`b) - -instanceMultiplicativeMonoidm=>MultiplicativeMonoid(FromStringm)where -one=FromStringone -FromStringa`times`FromStringb=FromString(a`times`b) +,Seminearring +)where + +importData.Monoid.Additive +importData.FingerTree +importData.Monoid.Self +importData.Monoid.FromString +importData.Monoid.Generator +importData.Foldable +importqualifiedData.SequenceasSeq +importData.Sequence(Seq) + +classMultiplicativeMonoidmwhere +one::m +times::m->m->m + +class(MultiplicativeMonoidm,Monoidm)=>Seminearringm + +instanceMonoidm=>MultiplicativeMonoid[m]where +one=[mempty] +xss`times`yss=[xs`mappend`ys|xs<-xss,ys<-yss] + +instanceMonoidm=>Seminearring[m] + +instance(Measuredvm,Monoidm)=>MultiplicativeMonoid(FingerTreevm)where +one=singletonmempty +xss`times`yss=getSelf$mapReduce(flipfmap'yss.mappend)xss + +instance(Monoidm)=>MultiplicativeMonoid(Seqm)where +one=Seq.singletonmempty +xss`times`yss=getSelf$mapReduce(flipfmapyss.mappend)xss + +instance(Measuredvm,Monoidm)=>Seminearring(FingerTreevm) + +instanceMultiplicativeMonoidm=>MultiplicativeMonoid(Selfm)where +one=Selfone +Selfa`times`Selfb=Self(a`times`b) + +instanceMultiplicativeMonoidm=>MultiplicativeMonoid(FromStringm)where +one=FromStringone +FromStringa`times`FromStringb=FromString(a`times`b) + +-- class Absorbing m where isZero :: m -> Bool hunk ./dist/doc/html/monoids/src/Data-Monoid-Reducer.html 22 - --- minimal definition unit or snoc -classMonoidm=>Reducercmwhere -unit::c->m -snoc::m->c->m -cons::c->m->m - -unit=snocmempty -snocm=mappendm.unit -cons=mappend.unit - -foldMapReduce::(Foldablef,e`Reducer`m)=>(a->e)->fa->m -foldMapReducef=foldMap(unit.f) - -foldReduce::(Foldablef,e`Reducer`m)=>fe->m -foldReduce=foldMapunit - -instance(Reducercm,Reducercn)=>Reducerc(m,n)where -unitx=(unitx,unitx) -(m,n)`snoc`x=(m`snoc`x,n`snoc`x) -x`cons`(m,n)=(x`cons`m,x`cons`n) - -instance(Reducercm,Reducercn,Reducerco)=>Reducerc(m,n,o)where -unitx=(unitx,unitx,unitx) -(m,n,o)`snoc`x=(m`snoc`x,n`snoc`x,o`snoc`x) -x`cons`(m,n,o)=(x`cons`m,x`cons`n,x`cons`o) - -instance(Reducercm,Reducercn,Reducerco,Reducercp)=>Reducerc(m,n,o,p)where -unitx=(unitx,unitx,unitx,unitx) -(m,n,o,p)`snoc`x=(m`snoc`x,n`snoc`x,o`snoc`x,p`snoc`x) -x`cons`(m,n,o,p)=(x`cons`m,x`cons`n,x`cons`o,x`cons`p) - -instanceReducerc[c]where -unit=return -cons=(:) -xs`snoc`x=xs++[x] - -instanceReducerc()where -unit_=() -_`snoc`_=() -_`cons`_=() - -instanceReducerBoolAnywhere -unit=Any - -instanceReducerBoolAllwhere -unit=All - -instanceReducer(a->a)(Endoa)where -unit=Endo - -instanceMonoida=>Reducera(Duala)where -unit=Dual - -instanceNuma=>Reducera(Suma)where -unit=Sum - -instanceNuma=>Reducera(Producta)where -unit=Product - -instanceReducer(Maybea)(Firsta)where -unit=First - -instanceReducera(Firsta)where -unit=First.Just - -instanceReducer(Maybea)(Lasta)where -unit=Last - -instanceReducera(Lasta)where -unit=Last.Just - -instanceMeasuredva=>Monoid(FingerTreeva)where -mempty=empty -mappend=(><) - -instanceMeasuredva=>Reducera(FingerTreeva)where -unit=singleton -cons=(<|) -snoc=(|>) +importqualifiedData.SequenceasSeq +importData.Sequence(Seq) + +-- minimal definition unit or snoc +classMonoidm=>Reducercmwhere +unit::c->m +snoc::m->c->m +cons::c->m->m + +unit=snocmempty +snocm=mappendm.unit +cons=mappend.unit + +foldMapReduce::(Foldablef,e`Reducer`m)=>(a->e)->fa->m +foldMapReducef=foldMap(unit.f) + +foldReduce::(Foldablef,e`Reducer`m)=>fe->m +foldReduce=foldMapunit + +instance(Reducercm,Reducercn)=>Reducerc(m,n)where +unitx=(unitx,unitx) +(m,n)`snoc`x=(m`snoc`x,n`snoc`x) +x`cons`(m,n)=(x`cons`m,x`cons`n) + +instance(Reducercm,Reducercn,Reducerco)=>Reducerc(m,n,o)where +unitx=(unitx,unitx,unitx) +(m,n,o)`snoc`x=(m`snoc`x,n`snoc`x,o`snoc`x) +x`cons`(m,n,o)=(x`cons`m,x`cons`n,x`cons`o) + +instance(Reducercm,Reducercn,Reducerco,Reducercp)=>Reducerc(m,n,o,p)where +unitx=(unitx,unitx,unitx,unitx) +(m,n,o,p)`snoc`x=(m`snoc`x,n`snoc`x,o`snoc`x,p`snoc`x) +x`cons`(m,n,o,p)=(x`cons`m,x`cons`n,x`cons`o,x`cons`p) + +instanceReducerc[c]where +unit=return +cons=(:) +xs`snoc`x=xs++[x] + +instanceReducerc()where +unit_=() +_`snoc`_=() +_`cons`_=() + +instanceReducerBoolAnywhere +unit=Any + +instanceReducerBoolAllwhere +unit=All + +instanceReducer(a->a)(Endoa)where +unit=Endo + +instanceMonoida=>Reducera(Duala)where +unit=Dual + +instanceNuma=>Reducera(Suma)where +unit=Sum + +instanceNuma=>Reducera(Producta)where +unit=Product + +instanceReducer(Maybea)(Firsta)where +unit=First + +instanceReducera(Firsta)where +unit=First.Just + +instanceReducer(Maybea)(Lasta)where +unit=Last + +instanceReducera(Lasta)where +unit=Last.Just + +-- orphan, which should be in Data.FingerTree +instanceMeasuredva=>Monoid(FingerTreeva)where +mempty=empty +mappend=(><) + +instanceMeasuredva=>Reducera(FingerTreeva)where +unit=singleton +cons=(<|) +snoc=(|>) + +instanceReducera(Seqa)where +unit=Seq.singleton +cons=(Seq.<|) +snoc=(Seq.|>) hunk ./dist/doc/html/monoids/src/Data-Monoid-Self.html 16 -importData.Foldable -importData.Monoid.Reducer -importData.Monoid.Generator -importGHC.Exts +importData.Monoid.Reducer +importData.Monoid.Generator + +newtypeSelfm=Self{getSelf::m}deriving(Monoid) hunk ./dist/doc/html/monoids/src/Data-Monoid-Self.html 21 -newtypeSelfm=Self{getSelf::m}deriving(Monoid) - -instanceMonoidm=>Reducerm(Selfm)where -unit=Self - -instanceFunctorSelfwhere -fmapf=Self.f.getSelf - -instancePointedSelfwhere -point=Self - -instanceCopointedSelfwhere -extract=getSelf - +instanceMonoidm=>Reducerm(Selfm)where +unit=Self + +instanceFunctorSelfwhere +fmapf=Self.f.getSelf + +instancePointedSelfwhere +point=Self + +instanceCopointedSelfwhere +extract=getSelf + }
show/hide Instances
Monoid m => Seminearring ([] m)
(Measured v m, Monoid m) => Seminearring (FingerTree v m)
Seminearring