2

我尝试修改 Yesod 项目,遇到了一个奇怪的错误。首先,我将介绍工作表单代码,以及带有错误消息的基本损坏代码。

type PForm x = ProductConfig -> Html -> MForm ReScheduler ReScheduler (FormResult x, Widget)

接下来的工作代码

productForm :: PForm SelectedProduct
productForm config extra = do
   let pInfo' = pInfo config
       aDays' = aDays config
       products = (catMaybes . pNametoText) pInfo'
       versions' = map consVersionPair pInfo'
   productInfo <- mapM generateSelectFields versions'
   (dateRes, dateView) <- mreq (selectField aDays') "placeHolder" Nothing
   (mailRes, mailView) <- mreq emailField "E-Mail Address" Nothing
   (noteRes, noteView) <- mreq textareaField
                               "Notes"
                               Nothing
   let productVersion = reduceFormResults $
                        map flagSelected $
                        map fst productInfo

       versionViews = map snd productInfo
   let widget =
          toWidget $(widgetFile "firmware") :: Widget


   return (makeSelected productVersion dateRes mailRes noteRes, widget)

上面的代码工作正常。这是损坏的代码,然后是错误和一些观察结果。

type RForm x = [KeyJobPair] -> Html -> MForm ReScheduler ReScheduler (FormResult x, Widget)

statusForm :: RForm ModData
statusForm kjPairs extra = do
--    let bPairs = buttonPairs kjPairs
--        statusPairs = map (pack . show &&& id) $
--                      ([minBound .. maxBound] :: [Status])
--    (jobRes,jobView) <- mreq (radioField bPairs) "Scheduled Jobs" Nothing
--    (mailRes, mailView) <- mreq emailField "E-Mail Address" Nothing
--    (noteRes, noteView) <- mreq textareaField "Notes" Nothing
--    (statusRes, statusView) <- mreq (selectField statusPairs) "Status" Nothing
--    let widget = toWidget [hamlet|<p> testing |]
    let widget = (toWidget $(widgetFile "status" )) :: Widget
    return (ModData <$> undefined <*> undefined <*> undefined, widget)


Handler/Manager.hs:109:19:
 No instance for (ToWidget
               ReScheduler ReScheduler (GGWidget master0 m0 ()))
  arising from a use of `toWidget'
Possible fix:
  add an instance declaration for
  (ToWidget ReScheduler ReScheduler (GGWidget master0 m0 ()))
In the expression: (toWidget ($(widgetFile "status"))) :: Widget
In an equation for `widget':
    widget = (toWidget ($(widgetFile "status"))) :: Widget
In the expression:
  do { let widget = ...;
       return
         (ModData <$> undefined <*> undefined <*> undefined, widget) }

请注意注释掉的硬编码 hamlet 代码。这编译得很好。这使我相信问题在于widgetFile,而不是toWidget。我在 Yesod 博客中指出,有时widgetFile需要显式:: Widget类型签名。我无法让它工作。也许这只是一个语法问题。欢迎反馈。与此同时,我可以只使用硬编码的哈姆雷特。

4

1 回答 1

2

这是一个语法问题。这是类型签名的正确放置问题。

let widget = toWidget ($(widgetFile "status") :: Widget)

这是对的。

于 2012-01-17T22:21:21.157 回答