我想做什么?
在ghci下打印格式和作者的关联列表 见doc:
writers :: [(String, Writer)]
Association list of formats and writers.
已尝试的内容
zurgl>>>import Text.Pandoc as P
zurgl>>>P.writers
<interactive>:20:1:
No instance for (Show (WriterOptions -> Pandoc -> [Char]))
arising from a use of `print'
Possible fix:
add an instance declaration for
(Show (WriterOptions -> Pandoc -> [Char]))
In a stmt of an interactive GHCi command: print it
我希望自动导入相应的show实例,但似乎并非如此。我必须承认我没有任何线索如何为(Show(WriterOptions - &gt; Pandoc - &gt; [Char])定义实例声明。作为解决方法,我试图导入Pandoc库的附加模块,但仍然没有可用的Show实例。
然后我应该自己定义这个实例吗? 如果是,请告诉您与我分享完成此任务的任何提示 如果我不应该是什么问题?
提前感谢您的帮助。
编辑
好吧,我想我看到了我的误解:
做:
zurgl>>>map (\x-> fst x) P.writers
["native","json","html","html5","html+lhs","html5+lhs","s5","slidy","slideous","dzslides","docbook","opendocument","latex","latex+lhs","beamer","beamer+lhs","context","texinfo","man","markdown","markdown+lhs","plain","rst","rst+lhs","mediawiki","textile","rtf","org","asciidoc"]
我认为尝试在我的元组中显示第二个东西是没有意义的。它似乎是一个功能,然后我们无法显示它。
我想这应该是问题所在。
答案 0 :(得分:2)
我尝试做的事情毫无意义,因为元组包含两种不同的类型 第一个是特定编写器的标识符(类型为字符串),第二个是编写器本身(然后是函数)。当然,如果我尝试打印所有这些,它将失败,因为没有显示功能。
然后要检索Pandoc中可用编写器的列表(目的是动态调用相应的函数),我们只需检索标识符列表,如下:
zurgl>>>map fst P.writers
["native","json","html","html5","html+lhs","html5+lhs","s5","slidy","slideous","dzslides","docbook","opendocument","latex","latex+lhs","beamer","beamer+lhs","context","texinfo","man","markdown","markdown+lhs","plain","rst","rst+lhs","mediawiki","textile","rtf","org","asciidoc"]