我尝试了以下内容:
sendResponseStatus status403 $ (defaultLayout [whamlet|Foo|] :: Handler Html)
这给了我这种类型的错误:
<interactive>:1:1: Warning:
Could not deduce (ToTypedContent (Handler Html))
arising from a use of ‘sendResponseStatus’
from the context (MonadHandler m)
bound by the inferred type of it :: MonadHandler m => m a
at <interactive>:1:1
In the expression: sendResponseStatus status403
In the expression:
sendResponseStatus status403
$ (defaultLayout
((asWidgetT . toWidget)
((blaze-markup-0.7.0.3:Text.Blaze.Internal.preEscapedText
. Data.Text.pack)
"Foo")) ::
Handler Html)
答案 0 :(得分:2)
事实证明,sendResponseStatus
并不期望Handler Html
,而是Html
正常工作:
html <- defaultLayout [whamlet|Foo|]
sendResponseStatus status403 html
为我编译并按预期执行。
将这种逻辑封装起来也是有意义的:
sendResponseStatusHandler :: (ToTypedContent c, MonadHandler m) => Status -> m c -> m b
sendResponseStatusHandler status handler = do
response <- handler
sendResponseStatus status response
因为能够传递Handler
对我来说似乎有点强大。