Frage

I tried modifying a Yesod project, and came across a weird error. First I will present the working form code, and the bare-bones broken code with error message.

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

working code next

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)

The above code works fine. Here's the broken code, followed by the error and some observations.

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) }

Note the commented out hard-coded hamlet code. This compiles fine. This leads me to believe the problem lies with widgetFile, not toWidget. I noted in the Yesod blog, that sometimes widgetFile wants an explicit :: Widget type signature. I haven't been able to get this to work. Maybe this is just a syntax problem. Feedback would be welcome. In the meantime I can just use hardcoded Hamlet.

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top