-
Notifications
You must be signed in to change notification settings - Fork 67
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
work with any MonadIO fixing #104 #105
Conversation
@tarleb what do you think of this change? One query. Instead of class ToJSONFilter m a where
toJSONFilter :: a -> m () would it make sense to do class ToJSONFilter a where
toJSONFilter :: forall m. MonadIO m => a -> m () ? (I suppose maybe the former is more flexible, as it allows one to define instances for non MonadIO monads, and even non-monad functors.) |
instance (Walkable a Pandoc) => ToJSONFilter IO (a -> a) where | ||
toJSONFilter f = BL.getContents >>= | ||
BL.putStr . encode . (walk f :: Pandoc -> Pandoc) . either error id . | ||
eitherDecode' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this? After all, IO is an instance of MonadIO, so this is already covered by lines 111-115, isn't it?
Ditto for the other IO instance below.
I guess I'd prefer the |
Is there any particular reason favoring the forall approach? |
I left out my reasoning intentionally, as I don't have a good answer for that. The universally quantified variant seems cleaner and more focused to me. The extra flexibility that comes with the multiparam typeclass variant probably won't be necessary for most users. |
I think most users won't touch this at all, or even know about it. Seems to me that non-MonadIO instances are conceivable -- e.g. for Conduit or pipes or any streaming abstraction that can receive input and give output. |
The original reason to do this was to also work for example with a |
It should work fine either way with |
Yes, but if |
Maybe I'm misunderstanding. If we have class ToJSONFilter a where
toJSONFilter :: forall m. MonadIO m => a -> m () Then class ToJSONFilter m a where
toJSONFilter :: a -> m () because |
I'm going to merge this and remove the unnecessary IO instance in a second commit. |
This is covered already by the MonadIO instance. Revises #105.
Previously a pure function `a -> a` could only be promoted to a filter in IO. Now we allow it to work with any instance of MonadIO. (This adds to #105.)
This went missing after my ill-considered revision to #105, commit 183af9d . See jgm/pandoc#8976.
Fixing #104