【发布时间】:2013-12-09 12:38:40
【问题描述】:
我想做一些类似于我在下面尝试的事情。似乎我需要了解更多关于 Monads 的信息。任何指针?
我确实使用yesod init 开始工作并使用yesod add-handler 创建处理程序。
在Handler/Hello.hs:
getHelloR :: Handler Html
getHelloR = do
let hello = "Hello World"
defaultLayout $ do
$(widgetFile "hello")
在templates/hello.hamlet:
<h1>Test
<p>#{hello}
我在运行cabal-dev install && yesod --dev devel 时遇到的错误
是:
Handler/Hello.hs:9:11:
Ambiguous type variable `a0' in the constraints:
(Data.String.IsString a0)
arising from a use of `hello' at Handler/Hello.hs:9:11-28
(blaze-markup-0.5.1.5:Text.Blaze.ToMarkup a0)
arising from a use of `toHtml' at Handler/Hello.hs:9:11-28
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `toHtml', namely `hello'
In the first argument of `asWidgetT . toWidget', namely
`toHtml hello'
In a stmt of a 'do' block: (asWidgetT . toWidget) (toHtml hello)
【问题讨论】:
-
您遇到什么错误?您是否使用“yesod init”进行了初始化?如果这样做,它将创建一个应该工作的骨架(如果没有向我们显示错误),然后您可以将其变形为您的代码(它将非常接近您已经编写的内容,除了 .hamlet 文件将是更加充实,但您可以从中删除所有内容。
-
@jamshidh 刚刚更新了这个问题。谢谢