Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why MonadWriter instance for ChronicleT uses underlying monad #68

Open
mutantmell opened this issue Oct 26, 2016 · 4 comments
Open

Why MonadWriter instance for ChronicleT uses underlying monad #68

mutantmell opened this issue Oct 26, 2016 · 4 comments

Comments

@mutantmell
Copy link

mutantmell commented Oct 26, 2016

ChronicleT seems like it can be made a valid MonadWriter, without relying on the underlying monad.

If it is not, it should be documented.

@mutantmell
Copy link
Author

mutantmell commented Oct 26, 2016

This seems to be a valid instance of MonadWriter:

instance (Monoid c, Semigroup c, Monad m) => MonadWriter c (ChronicleT c m) where
    tell = dictate

    listen (ChronicleT m) = ChronicleT $ do
      a <- m
      case a of
        This  x   -> return $ This x
        That    y -> return $ These mempty (y, mempty)
        These x y -> return $ These x (y, x)

    pass (ChronicleT m) = ChronicleT $ do
      a <- m
      case a of
        This  x       -> return $ This x
        That    (a,f) -> return $ These (f mempty) a
        These x (a,f) -> return $ These (f x) a

    writer (a,w) = ChronicleT $ return $ These w a

@phadej
Copy link
Collaborator

phadej commented Oct 26, 2016

MonadReader or MonadWriter ?

@mutantmell
Copy link
Author

MonadWriter, sorry

@mutantmell mutantmell changed the title Why MonadReader instance for ChronicleT uses underlying monad Why MonadWriter instance for ChronicleT uses underlying monad Oct 26, 2016
@phadej
Copy link
Collaborator

phadej commented Dec 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants