我正在尝试编写自定义的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
答案 0 :(得分:0)
您返回的Widget
类型实际上是:
WidgetT App IO ()
因此,Widget
(仅存在App
)与emailView
(存在于被提升的HandlerT Auth (HandlerT App IO)
monad中)之间存在不匹配。
解决这个问题:
registrationForm :: Html -> MForm (HandlerT App IO) (FormResult UserForm, Widget)
lift
,但在您已为表单调用相应的run
函数后