为什么一个使用toWidget工作,另一个不工作

时间:2012-01-17 22:12:26

标签: haskell yesod

我尝试修改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) }

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

1 个答案:

答案 0 :(得分:2)

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

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

这是正确的。