What is a good name for this state-like monad

This is something like a combination of State and Writer . I checked the laws of the monad.

 newtype M sa = M { runM :: s -> (s,a) } instance (Monoid s) => Monad (M s) where return = M . const . (mempty,) m >>= f = M $ \s -> let (s' ,x) = runM ms (s'',y) = runM (fx) (s `mappend` s') in (s' `mappend` s'', y) 

StateWriter seems kind.

+7
source share
3 answers

"Introspective writer"? It seems that the interesting thing you can do with it (which you cannot do with Writer) is to write an introspect function that checks the status / output and modifies it:

 introspect :: (s -> s) -> M s () introspect f = M $ \s -> (fs, ()) 

I don’t see that you can do this for a writer, I think you have to do it with a post-transformer:

 postW :: Writer wa -> (w -> w) -> Writer wa postW ma f = Writer $ let (w,a) = getWriter ma in (fw,a) 
+3
source

Monoidal State . MonoState . MState . AccumState

+2
source

Maybe call SW (Statefull Writer), I think the short names are pretty intuitive and retain some typing.

0
source

All Articles