mtl icon indicating copy to clipboard operation
mtl copied to clipboard

`AccumT` is a regular transformer and should have a regular `MonadAccum` instance.

Open jumper149 opened this issue 2 years ago • 6 comments
trafficstars

I think this was accidentaly copy-pasted, see #140 .

I don't see any problem with doing it this way. Maybe you can spot anything?

jumper149 avatar Jan 13 '23 11:01 jumper149

Moving this here just so that it doesn't get lost (from #140):

Edit: I don't understand why the MonadAccum instance for AccumT also uses Identity as a base monad. I think it should be fine with any monad, right?

Not unless you want to overlap on the monoid instance. Every Monad may admit any number of accumulating monoids, so the general instance is not supplied. This is a case where we ask not "can we?" but "should we?".

This discussion should move to #141.


My motivation was WriterT in this case.

instance (Monoid w, Monad m) => MonadWriter (WriterT w m)

I also feel like this is the way, that all transformers instances work (except for SelectT). Even ContT is sort of like that.


So if you would argue to keep Monoid w => MonadAccum w (AccumT w Identity), then you should also argue for Monoid w => MonadWriter (WriterT w Identity), right?

Well I think the way that WriterT does it currently is better.

jumper149 avatar Jan 14 '23 00:01 jumper149

My motivation was WriterT in this case. I also feel like this is the way, that all transformers instances work (except for SelectT). Even ContT is sort of like that.

Sorry, I'm confused as to why you feel this is "the way"? What way? Are you making the argument that it's always the case that (Monoid w, Monad m) => work as constraints for Writer and Accum? Have you checked the laws? I'm finding that (->) t is a counter example to the laws for MonadAccum for all monoids except (). I suspect that this is the case for Writer as well, but I'll have to write the equations down.

If this is not the case and you've found a way to make it work, do you mind presenting your work and showing us that the laws pass?

emilypi avatar Jan 14 '23 06:01 emilypi

Have you checked the laws?

I did the work: https://felixspringer.xyz/homepage/blog/accumtsMonadaccumInstance


I'm finding that (->) t is a counter example to the laws for MonadAccum for all monoids except ().

I didn't check this in particular, but considering that I just proved it for any base monad your finding cannot be true (unless I made a mistake of course, so please thoroughly check it).

jumper149 avatar Jan 14 '23 22:01 jumper149

This looks like a fine change to me. I'm also puzzled why Identity is in this instance in the first place.

Lysxia avatar Jan 14 '23 23:01 Lysxia

@jumper149 I believe i was looking at the PR last night and proved something else for something entirely unrelated to the PR. I checked again and yes, your proof is fine, thanks for providing it. It seems like this would be fine!

emilypi avatar Jan 15 '23 00:01 emilypi

Any updates on this? I wonder why is this not merged still after 2 years

Futarimiti avatar Dec 25 '24 20:12 Futarimiti

I believe this could be merged as-is, right?

turion avatar Sep 15 '25 08:09 turion

It looks good and is redundant with #168 @turion.

Thanks for the PR @jumper149 and sorry about the delay.

sjshuck avatar Sep 15 '25 21:09 sjshuck

No worries, it's nice to see some progress :)

Thanks for maintaining

jumper149 avatar Sep 15 '25 21:09 jumper149