关于pandoc:无法编译Haskell程序(“无法匹配”错误)

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

我试图在此处实施John MacFarlane的Haskell解决方案,这应该允许我在保留数学运算的同时将具有MathJax(latex)输入的HTML文件转换为.tex。 脚本是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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

我安装了Haskell的64位OSX版本,还给出了命令cabal install pandoc以获取pandoc函数。 但是,执行后

1
ghc --make fixmath.hs

我收到以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[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

出了什么问题我该怎么办?


pandoc的最新版本更改了RawBlock和RawInline的"格式"类型。 如果将"html""tex"替换为(Format"html")(Format"tex"),应该可以。 (假设除了编译器标记的问题之外,没有其他问题。)