
Related:
In Data.Monoid there is the 'Endo' newtype, which wraps functions of type 'a -> a'. Is there an 'EndoM' variant, or is that something that's usually created by putting other pieces together? Below is a sketch of what I mean:
-- Maybe this is known by another name? newtype EndoM f a = EndoM { appEndoM :: a -> f a }
-- Bind typeclass is from package semigroupoids. -- It means "Monad sans 'return'". -- Maybe use Monad f => here instead if getting the Bind instances is -- too annoying? (e.g., Writing orphan instances). instance Bind f => Semigroup (EndoM f a) where EndoM f <> EndoM g = EndoM $ f ->- g
-- Bind is not a superclass of Monad, so we get this awkward set of -- required constraints here. instance (Bind f, Monad f) => Monoid (EndoM f a) where mempty = EndoM pure
-- Jack
Not undervaluing this post, but to be clear to the OP, all of that really isn't adding any capabilities, just reifying the ones that others exposed. (You can use foldMap instead of foldr). This could be useful if you want to do higher-level stuff with it later on, but for the purposes of the original post I think it really is overkill, isn't it? -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.