Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to compile Haskell program ("Couldn't match" errors)

I'm trying to implement the Haskell solution by John MacFarlane here, which should allow me to convert HTML files with MathJax (latex) input to .tex while preserving the math. The script is:

import Text.Pandoc

main = toJsonFilter fixmath

fixmath :: Block -> Block
fixmath = bottomUp fixmathBlock . bottomUp fixmathInline

fixmathInline :: Inline -> Inline
fixmathInline (RawInline "html" ('<':'!':'-':'-':'M':'A':'T':'H':xs)) =
  RawInline "tex" $ take (length xs - 3) xs
fixmathInline x = x

fixmathBlock :: Block -> Block
fixmathBlock (RawBlock "html" ('<':'!':'-':'-':'M':'A':'T':'H':xs)) =
  RawBlock "tex" $ take (length xs - 3) xs
fixmathBlock x = x

I installed the 64-bit OSX version of Haskell, and also gave the command cabal install pandoc to get the pandoc functions. However, upon executing

ghc --make fixmath.hs

I get the following error:

[1 of 1] Compiling Main             ( fixmath.hs, fixmath.o )

fixmath.hs:9:26:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the pattern: "html"
    In the pattern:
      RawInline "html"
                ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs)
    In an equation for `fixmathInline':
        fixmathInline
          (RawInline "html"
                     ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs))
          = RawInline "tex" $ take (length xs - 3) xs

fixmath.hs:10:13:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the first argument of `RawInline', namely `"tex"'
    In the expression: RawInline "tex"
    In the expression: RawInline "tex" $ take (length xs - 3) xs

fixmath.hs:14:24:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the pattern: "html"
    In the pattern:
      RawBlock "html"
               ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs)
    In an equation for `fixmathBlock':
        fixmathBlock
          (RawBlock "html"
                    ('<' : '!' : '-' : '-' : 'M' : 'A' : 'T' : 'H' : xs))
          = RawBlock "tex" $ take (length xs - 3) xs

fixmath.hs:15:12:
    Couldn't match expected type `Format' with actual type `[Char]'
    In the first argument of `RawBlock', namely `"tex"'
    In the expression: RawBlock "tex"
    In the expression: RawBlock "tex" $ take (length xs - 3) xs

What's gone wrong and what can I do?

like image 716
TSGM Avatar asked Jul 23 '26 19:07

TSGM


1 Answers

Recent versions of pandoc changed the type of the "format" for RawBlock and RawInline. If you replace "html" and "tex" with (Format "html") and (Format "tex"), you should be okay. (Assuming there aren't other problems besides the one the compiler flagged.)

like image 61
John MacFarlane Avatar answered Jul 25 '26 22:07

John MacFarlane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!