[Haskell-cafe] containers and maps
jwlato at gmail.com
Thu Aug 13 05:01:34 EDT 2009
On 8/13/09, Jake McArthur <jake.mcarthur at gmail.com> wrote:
> Jake McArthur wrote:
> > The monoids package offers something similar to this:
> > mapReduce :: (Generator c, Reducer e m) => (Elem c -> e) -> c -> m
> > If we take (Elem c) to be (item), (e) to be (item'), (c) to be (full), and
> (m) to be (full'), it's basically the same thing, and offers the same
> advantages as the ones you listed, as far as I can tell.
> Your example about uvector inspired me to try writing out the necessary
> instances for uvector:
> instance UA a => Monoid (UArr a) where
> mempty = emptyU
> mappend = appendU
> instance UA a => Reducer a (UArr a) where
> unit = singletonU
> snoc = snocU
> cons = consU
> instance UA a => Generator (UArr a) where
> type Elem (UArr a) = a
> mapTo f = foldlU (\a -> snoc a . f)
This looks to be essentially the same as the 'map' function in
ListLike, and suffers from the same problem. It won't have the
performance characteristics of the native map functions. Using e.g.
ByteStrings, you're recreating a ByteString by snoc'ing elements.
This might work with UVector (I intend to try it this evening); I
don't know how well the fusion framework will hold up in class
Still, the monoids package is very powerful (and I'd completely
forgotten it). Perhaps there's another approach that would work?
More information about the Haskell-Cafe