使用 yesod,如何发送带有自定义 HTTP 状态代码的 defaultLayout?

With yesod, how can one send defaultLayout with a custom HTTP status code?

我试过以下方法:

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)

事实证明 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 对我来说似乎更强大了。