[Haskell-cafe] Traversals of monomorphic containers (was: Re: mapM_ for bytestring)

Nicolas Trangez nicolas at incubaid.com
Mon Sep 2 12:53:18 CEST 2013


# Redirected to haskell-cafe

On Sun, 2013-09-01 at 14:58 +0400, Artyom Kazak wrote:
> Would this be an appropriate place to propose adding mapM_ (and then  
> possibly mapM) to bytestring library?
> 
> Was it suggested before? If yes, why was it rejected?

This got me wondering: there are several type-classes useful for
polymorphic container types, e.g. Functor, Foldable & Traversable which
all apply to some type of kind (* -> *).

Are there related things for monomorphic containers, like ByteString,
Text or some newtype'd Vector with fixed element type, e.g.

class MFunctor f a where
    mfmap :: (a -> a) -> f -> f

instance MFunctor ByteString Word8 where
    mfmap = ByteString.map

or (maybe even better)

class MFunctor f where
    type Elem
    mfmap :: (Elem -> Elem) -> f -> f

instance MFunctor ByteString where
    type Elem = Word8
    mfmap = ByteString.map

and similar for other classes.

Nicolas





More information about the Haskell-Cafe mailing list