Drastic Prelude changes imminent
Gabriel Gonzalez
gabriel439 at gmail.com
Wed Feb 11 21:44:26 UTC 2015
Actually, I don't consider this instance a hack. One of the things that
convinced me of the elegance of this `Writer`-like instance for tuples
is that you can use it to implement another instance:
instance (Monoid a, Monoid b) => Monoid (a, b) where
mempty = pure mempty
mappend = liftA2 mappend
This is a special case of the more general pattern of lifting `Monoid`s
over `Applicative`s:
instance (Applicative f, Monoid b) => Monoid (f b) where
mempty = pure mempty
mappend = liftA2 mappend
On 2/11/15 1:01 PM, Henning Thielemann wrote:
> Am 01.02.2015 um 23:02 schrieb Edward Kmett:
>
>> On Sun, Feb 1, 2015 at 4:39 PM, Iavor Diatchki <iavor.diatchki at gmail.com
>> <mailto:iavor.diatchki at gmail.com>> wrote:
>>
>> Really? This is not obvious at all. Is it because of the odd
>> `Applicative` instance for pairs? I am saying 'odd' because there
>> are no similar instances for tuples of higher arity; there are also
>> no instance for `Monad` for the same type, which makes as much
>> sense, I guess. Obviously this is just an opinion, but I don't
>> think these instances fit pairs naturally, and make for confusing
>> looking code.
>>
>>
>> instance Monoid m => Monad ((,) m)
>>
>> is the "unnamed" writer monad that corresponds to the
>
>
> That looks like a hack which requires another hack (namely moving
> Monoid to Prelude). Would it have been too difficult to use the Writer
> monad from transformers or mtl? Btw. I think if I use this instance
> this is certainly by accident. I prefer to be explicit about my
> programming intentions and would use the Writer monad.
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
More information about the Libraries
mailing list