Artyom Kazak | 1 Sep 12:58 2013

mapM_ for bytestring

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?
Nicolas Trangez | 2 Sep 12:53 2013

Traversals of monomorphic containers (was: Re: mapM_ for bytestring)

# 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
(Continue reading)

Mario Blažević | 4 Sep 04:48 2013
Picon

Re: Traversals of monomorphic containers

On 09/02/13 06:53, Nicolas Trangez wrote:
> # 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

	I'm not aware of this particular class, but I have considered it. In 
the end I've chosen to generalize the class to FactorialMonoid instead:

class Monoid m => FactorialMonoid m where
    ...
    foldMap :: Monoid n => (m → n) → m → n

	ByteString and Text are instances of the class, and so are lists, maps, 
(Continue reading)

Tony Morris | 4 Sep 05:42 2013
Picon

Re: Traversals of monomorphic containers

These questions are exactly what Control.Lens answers.

On 04/09/2013 12:50 PM, "Mario Blažević" <blamario <at> acanac.net> wrote:
On 09/02/13 06:53, Nicolas Trangez wrote:
# 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


        I'm not aware of this particular class, but I have considered it. In the end I've chosen to generalize the class to FactorialMonoid instead:

class Monoid m => FactorialMonoid m where
   ...
   foldMap :: Monoid n => (m → n) → m → n

        ByteString and Text are instances of the class, and so are lists, maps, and other containers, and Sum and Product as well.


http://hackage.haskell.org/packages/archive/monoid-subclasses/0.3.2/doc/html/Data-Monoid-Factorial.html




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


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane