[Haskell-cafe] Traversals of monomorphic containers

Tony Morris tmorris at tmorris.net
Wed Sep 4 05:42:23 CEST 2013


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<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<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<http://www.haskell.org/mailman/listinfo/haskell-cafe>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130904/57a56c35/attachment.htm>


More information about the Haskell-Cafe mailing list