[auto ekmett@gmail.com**20090329184106] { hunk ./doc/html/monoids/Data-Group-Combinators.html 78 +>
Contents
Combinators +
QuickCheck Properties +
Synopsis
module Data.Group
replicate :: (Group m, Integral n) => m -> n -> m
prop_replicate_right_distributive :: (Eq g, Group g, Arbitrary g, Integral n) => g -> n -> n -> Bool
Combinators +QuickCheck Properties +,replicate -)where - -importPreludehiding(replicate) -importData.Group +-- * Combinators +,replicate +-- * QuickCheck Properties +,prop_replicate_right_distributive +)where hunk ./doc/html/monoids/src/Data-Group-Combinators.html 34 --- shamelessly stolen from Lennart Augustsson's post: --- http://augustss.blogspot.com/2008/07/lost-and-found-if-i-write-108-in.html --- adapted to groups, which can permit negative exponents -replicate::(Groupm,Integraln)=>m->n->m -replicatex0y0 -|y0<0=f(gnegatex0)(negatey0) -|y0==0=mempty -|otherwise=fx0y0 -where -fxy -|eveny=f(x`mappend`x)(y`quot`2) -|y==1=x -|otherwise=g(x`mappend`x)((y-1)`quot`2)x -gxyz -|eveny=g(x`mappend`x)(y`quot`2)z -|y==1=x`mappend`z -|otherwise=g(x`mappend`x)((y-1)`quot`2)(x`mappend`z) - +importPreludehiding(replicate) +importData.Group +importTest.QuickCheck + +-- shamelessly stolen from Lennart Augustsson's post: +-- http://augustss.blogspot.com/2008/07/lost-and-found-if-i-write-108-in.html +-- adapted to groups, which can permit negative exponents +replicate::(Groupm,Integraln)=>m->n->m +replicatex0y0 +|y0<0=f(gnegatex0)(negatey0) +|y0==0=mempty +|otherwise=fx0y0 +where +fxy +|eveny=f(x`mappend`x)(y`quot`2) +|y==1=x +|otherwise=g(x`mappend`x)((y-1)`quot`2)x +gxyz +|eveny=g(x`mappend`x)(y`quot`2)z +|y==1=x`mappend`z +|otherwise=g(x`mappend`x)((y-1)`quot`2)(x`mappend`z) + +prop_replicate_right_distributive::(Eqg,Groupg,Arbitraryg,Integraln)=>g->n->n->Bool +prop_replicate_right_distributivegxy +=replicateg(x+y)==replicategx`mappend`replicategy hunk ./doc/html/monoids/src/Data-Monoid-Combinators.html 55 -)where - -importPreludehiding(mapM_,any,elem,filter,concatMap,and,or,all,sum,product,notElem,replicate,cycle,repeat) -importControl.Applicative -importData.Monoid.Generator -importData.Monoid.Applicative -importData.Monoid.Self -importData.Monoid.Monad - --- | Efficiently 'mapReduce' a 'Generator' using the 'Traversal' monoid. A specialized version of its namesake in "Data.Foldable" -traverse_::(Generatorc,Applicativef)=>(Elemc->fb)->c->f() -traverse_f=getTraversal.mapReducef - --- | flipped 'traverse_' as in "Data.Foldable" -for_::(Generatorc,Applicativef)=>c->(Elemc->fb)->f() -for_=fliptraverse_ - --- | Efficiently 'mapReduce' a 'Generator' using the 'Action' monoid. A specialized version of its namesake from "Data.Foldable" and "Control.Monad" -mapM_::(Generatorc,Monadm)=>(Elemc->mb)->c->m() -mapM_f=getAction.mapReducef - --- | flipped 'mapM_' as in "Data.Foldable" and "Control.Monad" -forM_::(Generatorc,Monadm)=>c->(Elemc->mb)->m() -forM_=flipmapM_ - --- | Efficiently 'mapReduce' a 'Generator' using the 'Self' monoid. A specialized version of its namesake from "Data.Foldable" -foldMap::(Monoidm,Generatorc)=>(Elemc->m)->c->m -foldMapf=getSelf.mapReducef - --- | Efficiently 'reduce' a 'Generator' using the 'Self' monoid. A specialized version of its namesake from "Data.Foldable" -fold::(Monoidm,Generatorc,Elemc~m)=>c->m -fold=getSelf.reduce - --- | A further specialization of "foldMap" -concatMap::Generatorc=>(Elemc->[b])->c->[b] -concatMap=foldMap - --- | Efficiently 'reduce' a 'Generator' that contains values of type 'Bool' -and::(Generatorc,Elemc~Bool)=>c->Bool -and=getAll.reduce - --- | Efficiently 'reduce' a 'Generator' that contains values of type 'Bool' -or::(Generatorc,Elemc~Bool)=>c->Bool -or=getAny.reduce - --- | Efficiently 'mapReduce' any 'Generator' checking to see if any of its values match the supplied predicate -any::Generatorc=>(Elemc->Bool)->c->Bool -anyf=getAny.mapReducef - --- | Efficiently 'mapReduce' any 'Generator' checking to see if all of its values match the supplied predicate -all::Generatorc=>(Elemc->Bool)->c->Bool -allf=getAll.mapReducef - --- | Efficiently 'mapReduce' any 'Generator' using the 'Sum' 'Monoid' -sum::(Generatorc,Num(Elemc))=>c->Elemc -sum=getSum.reduce - --- | Efficiently 'mapReduce' any 'Generator' using the 'Product' 'Monoid' -product::(Generatorc,Num(Elemc))=>c->Elemc -product=getProduct.reduce - --- | Check to see if 'any' member of the 'Generator' matches the supplied value -elem::(Generatorc,Eq(Elemc))=>Elemc->c->Bool -elem=any.(==) - --- | Check to make sure that the supplied value is not a member of the 'Generator' -notElem::(Generatorc,Eq(Elemc))=>Elemc->c->Bool -notElemx=not.elemx - --- | Efficiently 'mapReduce' a subset of the elements in a 'Generator' -filter::(Generatorc,Elemc`Reducer`m)=>(Elemc->Bool)->c->m -filterp=foldMapfwhere -fx|px=unitx -|otherwise=mempty - --- | A specialization of 'filter' using the 'First' 'Monoid', analogous to 'Data.List.find' -find::Generatorc=>(Elemc->Bool)->c->Maybe(Elemc) -findp=getFirst.filterp - --- | A generalization of 'Data.List.replicate' to an arbitrary 'Monoid'. Adapted from --- <http://augustss.blogspot.com/2008/07/lost-and-found-if-i-write-108-in.html> -replicate::(Monoidm,Integraln)=>m->n->m -replicatex0y0 -|y0<0=mempty-- error "negative length" -|y0==0=mempty -|otherwise=fx0y0 -where -fxy -|eveny=f(x`mappend`x)(y`quot`2) -|y==1=x -|otherwise=g(x`mappend`x)((y-1)`quot`2)x -gxyz -|eveny=g(x`mappend`x)(y`quot`2)z -|y==1=x`mappend`z -|otherwise=g(x`mappend`x)((y-1)`quot`2)(x`mappend`z) - --- | A generalization of 'Data.List.cycle' to an arbitrary 'Monoid'. May fail to terminate for some values in some monoids. -cycle::Monoidm=>m->m -cyclexs=xs'wherexs'=xs`mappend`xs' - --- | A generalization of 'Data.List.repeat' to an arbitrary 'Monoid'. May fail to terminate for some values in some monoids. -repeat::(e`Reducer`m)=>e->m -repeatx=xswherexs=consxxs +-- * QuickCheck Properties +,prop_replicate_right_distributive +)where + +importPreludehiding(mapM_,any,elem,filter,concatMap,and,or,all,sum,product,notElem,replicate,cycle,repeat) +importControl.Applicative +importData.Monoid.Generator +importData.Monoid.Applicative +importData.Monoid.Self +importData.Monoid.Monad +importTest.QuickCheck + +-- | Efficiently 'mapReduce' a 'Generator' using the 'Traversal' monoid. A specialized version of its namesake in "Data.Foldable" +traverse_::(Generatorc,Applicativef)=>(Elemc->fb)->c->f() +traverse_f=getTraversal.mapReducef + +-- | flipped 'traverse_' as in "Data.Foldable" +for_::(Generatorc,Applicativef)=>c->(Elemc->fb)->f() +for_=fliptraverse_ + +-- | Efficiently 'mapReduce' a 'Generator' using the 'Action' monoid. A specialized version of its namesake from "Data.Foldable" and "Control.Monad" +mapM_::(Generatorc,Monadm)=>(Elemc->mb)->c->m() +mapM_f=getAction.mapReducef + +-- | flipped 'mapM_' as in "Data.Foldable" and "Control.Monad" +forM_::(Generatorc,Monadm)=>c->(Elemc->mb)->m() +forM_=flipmapM_ + +-- | Efficiently 'mapReduce' a 'Generator' using the 'Self' monoid. A specialized version of its namesake from "Data.Foldable" +foldMap::(Monoidm,Generatorc)=>(Elemc->m)->c->m +foldMapf=getSelf.mapReducef + +-- | Efficiently 'reduce' a 'Generator' using the 'Self' monoid. A specialized version of its namesake from "Data.Foldable" +fold::(Monoidm,Generatorc,Elemc~m)=>c->m +fold=getSelf.reduce + +-- | A further specialization of "foldMap" +concatMap::Generatorc=>(Elemc->[b])->c->[b] +concatMap=foldMap + +-- | Efficiently 'reduce' a 'Generator' that contains values of type 'Bool' +and::(Generatorc,Elemc~Bool)=>c->Bool +and=getAll.reduce + +-- | Efficiently 'reduce' a 'Generator' that contains values of type 'Bool' +or::(Generatorc,Elemc~Bool)=>c->Bool +or=getAny.reduce + +-- | Efficiently 'mapReduce' any 'Generator' checking to see if any of its values match the supplied predicate +any::Generatorc=>(Elemc->Bool)->c->Bool +anyf=getAny.mapReducef + +-- | Efficiently 'mapReduce' any 'Generator' checking to see if all of its values match the supplied predicate +all::Generatorc=>(Elemc->Bool)->c->Bool +allf=getAll.mapReducef + +-- | Efficiently 'mapReduce' any 'Generator' using the 'Sum' 'Monoid' +sum::(Generatorc,Num(Elemc))=>c->Elemc +sum=getSum.reduce + +-- | Efficiently 'mapReduce' any 'Generator' using the 'Product' 'Monoid' +product::(Generatorc,Num(Elemc))=>c->Elemc +product=getProduct.reduce + +-- | Check to see if 'any' member of the 'Generator' matches the supplied value +elem::(Generatorc,Eq(Elemc))=>Elemc->c->Bool +elem=any.(==) + +-- | Check to make sure that the supplied value is not a member of the 'Generator' +notElem::(Generatorc,Eq(Elemc))=>Elemc->c->Bool +notElemx=not.elemx + +-- | Efficiently 'mapReduce' a subset of the elements in a 'Generator' +filter::(Generatorc,Elemc`Reducer`m)=>(Elemc->Bool)->c->m +filterp=foldMapfwhere +fx|px=unitx +|otherwise=mempty + +-- | A specialization of 'filter' using the 'First' 'Monoid', analogous to 'Data.List.find' +find::Generatorc=>(Elemc->Bool)->c->Maybe(Elemc) +findp=getFirst.filterp + +-- | A generalization of 'Data.List.replicate' to an arbitrary 'Monoid'. Adapted from +-- <http://augustss.blogspot.com/2008/07/lost-and-found-if-i-write-108-in.html> +replicate::(Monoidm,Integraln)=>m->n->m +replicatex0y0 +|y0<0=mempty-- error "negative length" +|y0==0=mempty +|otherwise=fx0y0 +where +fxy +|eveny=f(x`mappend`x)(y`quot`2) +|y==1=x +|otherwise=g(x`mappend`x)((y-1)`quot`2)x +gxyz +|eveny=g(x`mappend`x)(y`quot`2)z +|y==1=x`mappend`z +|otherwise=g(x`mappend`x)((y-1)`quot`2)(x`mappend`z) + +-- | A generalization of 'Data.List.cycle' to an arbitrary 'Monoid'. May fail to terminate for some values in some monoids. +cycle::Monoidm=>m->m +cyclexs=xs'wherexs'=xs`mappend`xs' + +-- | A generalization of 'Data.List.repeat' to an arbitrary 'Monoid'. May fail to terminate for some values in some monoids. +repeat::(e`Reducer`m)=>e->m +repeatx=xswherexs=consxxs + +prop_replicate_right_distributive::(Eqm,Monoidm,Arbitrarym,Integraln)=>m->n->n->Bool +prop_replicate_right_distributivemxy +=replicatem(x+y)==replicatemx`mappend`replicatemy }
prop_replicate_right_distributive :: (Eq g, Group g, Arbitrary g, Integral n) => g -> n -> n -> BoolSource
QuickCheck Properties +
prop_replicate_right_distributive :: (Eq m, Monoid m, Arbitrary m, Integral n) => m -> n -> n -> Bool
QuickCheck Properties +
prop_replicate_right_distributive :: (Eq m, Monoid m, Arbitrary m, Integral n) => m -> n -> n -> BoolSource
prop_replicate_right_distributive
1 (Function)
2 (Function)