【发布时间】:2012-11-19 03:14:41
【问题描述】:
我正在尝试 Yesod 网页上记录的 Yesod 书籍示例。其中一个例子是Chat application embedded in Wiki。当我在 ghci 中尝试时(从包含 Wiki 示例代码的 Wiki.hs 加载 Chat 模块),我收到以下 Chat.hs 错误:
Chat.hs:122:34:
Could not deduce (Text.Julius.ToJavascript Text)
arising from a use of `Text.Julius.toJavascript'
from the context (YesodChat master)
bound by the type signature for
chatWidget :: YesodChat master =>
(Route Chat -> Route master) -> GWidget sub master ()
at Chat.hs:(81,15)-(83,35)
Possible fix:
add an instance declaration for (Text.Julius.ToJavascript Text)
In the first argument of `Text.Julius.Javascript', namely
`Text.Julius.toJavascript output'
In the expression:
Text.Julius.Javascript (Text.Julius.toJavascript output)
In the first argument of `Data.Monoid.mconcat', namely
`[Text.Julius.Javascript
((Data.Text.Lazy.Builder.fromText . Text.Shakespeare.pack')
"\
\// Set up the receiving end\
\var output = document.getElementById(\""),
Text.Julius.Javascript (Text.Julius.toJavascript output),
Text.Julius.Javascript
((Data.Text.Lazy.Builder.fromText . Text.Shakespeare.pack')
"\");\
\var src = new EventSource(\""),
Text.Julius.Javascript
(Data.Text.Lazy.Builder.fromText
(_render_a3Yr (toMaster ReceiveR) [])),
....]'
我对 Yesod 库还不是很熟悉。所以,我被上述错误难住了——我在其他 Yesod 示例中也看到了这个错误,其中调用了 toWidget 函数。所以,它似乎与toWidget 函数有关。我将感谢您在修复上述错误方面的帮助。
我正在使用 ghc 7.6.1 和 yesod 1.1.4.1。
更新:
按照 Hammar 的建议进行了修复。我在Chat.hs 中做了两处更改。
-
为 rawJS 添加导入语句:
import Text.Julius (rawJS) -
在
Chat.hs中跟踪julius whamlet内的所有#{} 块实例,并将它们替换为{# rawJS ...}var output = document.getElementById("#{rawJS output}");var input = document.getElementById("#{rawJS input}");
【问题讨论】: