[Proposal] Add instance Monoid a => Monoid (Const a b)

Dag Odenhall dag.odenhall at gmail.com
Sun Sep 29 18:12:57 UTC 2013


Cute trick; I've been wanting a way to get a product out of a set of folds.
+1


On Sun, Sep 29, 2013 at 6:13 PM, Edward Kmett <ekmett at gmail.com> wrote:

> A decent argument in favor is there really isn't another viable instance
> for it. Being able to glue together folds with (<>) never occurred to me.
>
> +1 from me
>
> -Edward
>
>
> On Sun, Sep 29, 2013 at 12:01 PM, <haskell at nand.wakku.to> wrote:
>
>> Hello,
>>
>> I think this a Monoid instance on Const would be useful. The motivation
>> comes
>> from ‘lens’, where folds come out as (a -> Const a a) -> s -> Const a s.
>> This
>> instance, together with the Monoid a => Monoid (r -> a) instance, allows
>> folds
>> themselves to be an instance of Monoid, allowing for some really pretty
>> code.
>>
>> Example of the instance body:
>>
>> > instance Monoid a => Monoid (Const a b) where
>> >   mempty = Const mempty
>> >   mappend (Const a) (Const b) = Const (mappend a b)
>>
>> Examples of it being used together with lens:
>>
>> >>> "Hello, world!" ^.. mconcat [ix 2, ix 7, ix 1]
>> "lwe"
>>
>> Discussion Period: 2 weeks
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> http://www.haskell.org/mailman/listinfo/libraries
>>
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20130929/b0de9797/attachment.html>


More information about the Libraries mailing list