Be sure to add type annotations to all your forms! This is why Michael Snoyman asked for the type of articleForm
. My subsite refused to typecheck with similar errors because I didn't annotate this function:
simpleSourceForm = DataSourceInput
<$> areq textField "Name" Nothing
<*> areq intField "Start" Nothing
<*> areq intField "End" Nothing
That gave me errors such as these:
Yesod\DataSource.hs:58:36:
Couldn't match type `m0' with `HandlerT m IO'
because type variable `m' would escape its scope
This (rigid, skolem) type variable is bound by
the type signature for
postDataSourceInputR :: YesodDataSource m =>
HandlerT DataSource (HandlerT m IO) Html
Yesod\DataSource.hs:49:7:
No instance for (RenderMessage (HandlerSite m0) FormMessage)
arising from a use of `areq'
In the second argument of `(<$>)', namely
`areq textField "Name" Nothing'
In the first argument of `(<*>)', namely
`DataSourceInput <$> areq textField "Name" Nothing'
In the first argument of `(<*>)', namely
`DataSourceInput <$> areq textField "Name" Nothing
<*> areq intField "Start" Nothing'
Yesod\DataSource.hs:30:22:
Could not deduce (m ~ HandlerSite m0)
from the context (YesodDataSource m)
bound by the type signature for
getDataSourceInputR :: YesodDataSource m =>
HandlerT DataSource (HandlerT m IO) Html
Annotating the function fixed everything:
simpleSourceForm :: YesodDataSource m => AForm (HandlerT m IO) DataSourceInput
simpleSourceForm = DataSourceInput
<$> areq textField "Name" Nothing
<*> areq intField "Start" Nothing
<*> areq intField "End" Nothing
(I'll also include the YesodDataSource typeclass for informational purposes)
class (RenderMessage master FormMessage, Yesod master) => YesodDataSource master