In trying to understand the MonadWriter class, I have been writing instance for different Monads, and then got stuck on Either
. I don’t see how to write listen
or pass
for the Left
constructor, as there is no way to create a value of type a
for the Left
constructor for listen
and pass
.
Is this instance possible?
instance (Monoid w) => MonadWriter w (Either w) where
tell :: w -> Either w ()
tell = Left
writer :: (a, w) -> Either w a
writer (a, _) = Right a
listen :: Either w a -> Either w (a, w)
listen (Right a) = Right (a, mempty)
listen (Left w) = ?
pass :: Either w (a, w -> w) -> Either w a
pass (Right (a, _)) = Right a
pass (Left _) = ?