Yesod fvInput 无法将 'App' 与 'Auth' 匹配

Yesod fvInput can't match 'App' with 'Auth'

我正在尝试编写自定义 Yesod 注册表。我遇到的问题是,当它到达 fvInput 时,它似乎使用的是 App 而不是 Auth。我不太确定应该如何处理,而且我似乎找不到它的术语。我试过在表单中​​以各种方式提升,但我只能让它抛出不同的错误。此外,唯一一次抛出此错误是在我有 fvInput 行时,但如果我删除它,则不会抛出任何错误并且它会正确编译。

代码:

registrationForm :: Html -> MForm (HandlerT Auth (HandlerT App IO)) (FormResult UserForm, Widget)
registrationForm extra = do
    (emailRes, emailView) <- mreq textField "" Nothing
    let userRes = UserForm <$> emailRes
    let widget = do
        [whamlet|
            #{extra}
            ^{fvInput emailView}
            <input type=Submit value="Registration">
        |]

    return (userRes, widget)

错误:

Foundation.hs:169:30:
    Couldn't match type ‘App’ with ‘Auth’
    In the second argument of ‘(GHC.Base..)’, namely ‘toWidget’
    In the expression: asWidgetT GHC.Base.. toWidget
    In a stmt of a 'do' block:
      (asWidgetT GHC.Base.. toWidget) (fvInput emailView)

提前感谢您的帮助!

mreq 之前的电梯错误:

Foundation.hs:166:49:
   Couldn't match type ‘HandlerT Auth (HandlerT App IO)’
               with ‘transformers-0.4.2.0:Control.Monad.Trans.RWS.Lazy.RWST
                       (Maybe (Env, FileEnv), HandlerSite m0, [Lang]) Enctype Ints m0’
    Expected type: HandlerT
                 Auth (HandlerT App IO) (FormResult Text, FieldView App)
      Actual type: MForm m0 (FormResult Text, FieldView App)
    In the second argument of ‘($)’, namely ‘mreq textField "" Nothing’
    In a stmt of a 'do' block:
      (emailRes, emailView) <- lift $ mreq textField "" Nothing

您返回的 Widget 类型实际上是:

WidgetT App IO ()

因此 Widget(只存在于 App 中)和 emailView(存在于提升的 HandlerT Auth (HandlerT App IO) monad 中)之间存在不匹配。

解决这个问题:

  1. 将您键入的签名更改为 registrationForm :: Html -> MForm (HandlerT App IO) (FormResult UserForm, Widget)
  2. 在使用站点,您很可能需要使用 lift,但是在您已经为表单调用了适当的 run 函数之后