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

toJSONFilter no longer supports non-monad list result #8976

Closed
elliottslaughter opened this issue Jul 30, 2023 · 3 comments
Closed

toJSONFilter no longer supports non-monad list result #8976

elliottslaughter opened this issue Jul 30, 2023 · 3 comments
Labels

Comments

@elliottslaughter
Copy link

I have been using the following filter on some of my documents. As of pandoc-types 1.23.0.1, this appears to no longer compile:

{-# LANGUAGE OverloadedStrings #-}
import Text.Pandoc.Definition
import Text.Pandoc.JSON

-- This pass strips <span class="remove">...</span>.
removeSpan :: Inline -> [Inline]
removeSpan (Span (_, ["remove"], _) _) = []
removeSpan x = [x]

main :: IO ()
main = toJSONFilter removeSpan

Error:

my_filter.hs:11:8: error:
    • No instance for (ToJSONFilter IO (Inline -> [Inline]))
        arising from a use of ‘toJSONFilter’
        (maybe you haven't applied a function to enough arguments?)
    • In the expression: toJSONFilter removeSpan
      In an equation for ‘main’: main = toJSONFilter removeSpan
   |
11 | main = toJSONFilter removeSpan
   |        ^^^^^^^^^^^^

After staring a bit at the documentation and source code for toJSONFilter, I came to the conclusion that this form is no longer supported and I need to add the IO monad to unbreak it. And indeed, this works:

{-# LANGUAGE OverloadedStrings #-}
import Text.Pandoc.Definition
import Text.Pandoc.JSON

-- This pass strips <span class="remove">...</span>.
removeSpan :: Inline -> IO [Inline]
removeSpan (Span (_, ["remove"], _) _) = return []
removeSpan x = return [x]

main :: IO ()
main = toJSONFilter removeSpan

It's not the most horrible change to need to make to my code, but it is (I think) a breaking change, and can cause users some needless effort, especially because the list form is not clearly demonstrated in the documentation of either the filters page or Hackage for toJSONFilter.

Versions, etc.:

$ pandoc --version
pandoc 3.1.4
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: .../pandoc
Copyright (C) 2006-2023 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

macOS 13.5

@jgm
Copy link
Owner

jgm commented Aug 4, 2023

See this change.

It sure looks like this commit removed a pure instance and added IO. I hadn't noticed that. If so it should be changed!

@jgm
Copy link
Owner

jgm commented Aug 4, 2023

@KommuSoft may want to comment.

@jgm
Copy link
Owner

jgm commented Aug 5, 2023

Ah, I think the problem was not @KommuSoft's commit but my revision. Will fix.

jgm added a commit to jgm/pandoc-types that referenced this issue Aug 5, 2023
This went missing after my ill-considered revision to #105,
commit 183af9d .

See jgm/pandoc#8976.
@jgm jgm closed this as completed in 9c1147f Aug 5, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Oct 30, 2023
[1.23.1]

  * Restore toJSONFilter instance for pure `a -> [a]`.
    This went missing after my ill-considered revision to #105,
    commit 183af9d9f1066be974ac55fd23a4c985999d3ce8 . See jgm/pandoc#8976.

  * Generalize ToJSONFilter instance. 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.)

  * Allow bytestring 0.12.

[1.23.0.1]

  * Allow aeson 2.2.

  * Remove dependency on string-qq (recbecca skinner).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants