Joar Leth
Joar Leth

Reputation: 701

Yesod generateFormPost - No instance for (RenderMessage master0 FormMessage)

I tried to follow this screencast by Michael Snoyman http://vimeo.com/39646807. However, it seems changes to the i18n causes that code to fail. I can't find any information on how to solve this problem on a scaffolded site and I can't quite make sense of the information given here http://www.yesodweb.com/book/internationalization.

This is the error i get, referring to code in Home.hs:

No instance for (RenderMessage master0 FormMessage)
  arising from a use of `generateFormPost'
Possible fix:
  add an instance declaration for (RenderMessage master0 FormMessage)
In a stmt of a 'do' block:
  (formWidget, enctype) <- generateFormPost noteForm
In the expression:
  do { (formWidget, enctype) <- generateFormPost noteForm;
       defaultLayout ($(widgetFile "notes")) }
In an equation for `getNotesR':
    getNotesR
      = do { (formWidget, enctype) <- generateFormPost noteForm;
             defaultLayout ($(widgetFile "notes")) }

The information seems pretty clear, the problem is I can't figure out how to add an instance declaration for (RenderMessage master0 FormMessage).

Here's the code I added to Home.hs

noteForm = renderBootstrap $ Note
    <$> areq textField "Title" Nothing
    <*> areq textField "Content" Nothing

getNotesR = do
    (formWidget, enctype) <- generateFormPost noteForm
    defaultLayout $(widgetFile "notes")

postNotesR = return ()
getNoteR noteId = return ()

Ant the following is from templates/notes.hamlet

<form method=post enctype=#{enctype}>
    ^{formWidget}
    <input type=submit>

Upvotes: 0

Views: 491

Answers (2)

sclv
sclv

Reputation: 38891

As a general proposition, when you see something like this:

No instance for (RenderMessage master0 FormMessage)

Bear in mind that master0 (or anything like it starting with a lowercase letter) is a free type variable that has not been instantiated to a concrete type. You can mentally replace it with a if that helps. So now we see that the message says there's no generic RenderMessage instance that is uniquely determined by FormMessage in the second parameter and an arbitrary type in the first parameter.

therefore, the usual way to fix this is to figure out what you want to instantiate the free type to, and to provide a type signature or other hint to fix it to that instantiation.

In this case, the type signature suggested by Michael Snoyman noteForm :: Form Note serves this purpose.

Upvotes: 2

tomferon
tomferon

Reputation: 4991

What about adding this code ?

instance RenderMessage [The name of your Yesod instance] FormMessage where
    renderMessage _ _ = defaultFormMessage

See http://www.yesodweb.com/book/internationalization.

Upvotes: 0

Related Questions