arpho
arpho

Reputation: 1646

yesod how to solve this error?

I am just started with Yesod, I am following this tutorial:http://yannesposito.com/Scratch/en/blog/Yesod-tutorial-for-newbies/ I get this error:

Handler/Blog.hs:32:17:
Couldn't match type `handler' with `GHandler App App'
  `handler' is a rigid type variable bound by
            the type signature for postBlogR :: handler RepHtml
            at Handler/Blog.hs:29:14
Expected type: handler [Entity Article]
  Actual type: GHandler App App [Entity Article]
In a stmt of a 'do' block:
  articles <- runDB $ selectList [] [Desc ArticleTitle]
In the expression:
  do { articles <- runDB $ selectList [] [Desc ArticleTitle];
       (articleWidget, enctype) <- generateFormPost entryForm;
       defaultLayout $ do { $(widgetFile "articles") } }
In an equation for `postBlogR':
    postBlogR
      = do { articles <- runDB $ selectList [] [Desc ArticleTitle];
             (articleWidget, enctype) <- generateFormPost entryForm;
             defaultLayout $ do { ... } }

this is my Blog.hs:

    module Handler.Blog
    ( getBlogR
    , postBlogR
    )
where

import Import

-- to use Html into forms
import Yesod.Form.Nic (YesodNic, nicHtmlField)
instance YesodNic App

entryForm :: Form Article
entryForm = renderDivs $ Article
    <$> areq   textField "Title" Nothing
    <*> areq   nicHtmlField "Content" Nothing

-- The view showing the list of articles
getBlogR :: Handler Html
getBlogR = do
    -- Get the list of articles inside the database.
    articles <- runDB $ selectList [] [Desc ArticleTitle]
    -- We'll need the two "objects": articleWidget and enctype
    -- to construct the form (see templates/articles.hamlet).
    (articleWidget, enctype) <- generateFormPost entryForm
    defaultLayout $ do
        $(widgetFile "articles")

postBlogR :: handler RepHtml
postBlogR = do
    -- Get the list of articles inside the database.
    articles <- runDB $ selectList [] [Desc ArticleTitle]
    -- We'll need the two "objects": articleWidget and enctype
    -- to construct the form (see templates/articles.hamlet).
    (articleWidget, enctype) <- generateFormPost entryForm
    defaultLayout $ do
        $(widgetFile "articles")

my routes:

    /static StaticR Static getStatic
/auth   AuthR   Auth   getAuth

/favicon.ico FaviconR GET
/robots.txt RobotsR GET

/ HomeR GET POST
/echo/#Text EchoR GET
/mirror MirrorR GET POST
/blog BlogR GET POST
/blog/#ArticleId ArticleR GET

and my models:

    User
    ident Text
    password Text Maybe
    UniqueUser ident
Email
    email Text
    user UserId Maybe
    verkey Text Maybe
    UniqueEmail email

Article
    title   Text
    content Html
    deriving

 -- By default this file is used in Model.hs (which is imported by Foundation.hs)

Upvotes: 2

Views: 391

Answers (1)

ichistmeinname
ichistmeinname

Reputation: 1500

I think, you just have to fix your type signature for postBlogR to Handler RepHtml. Names starting with lower case letters are reserved for type variables in type signatures, so it cannot be deduced right here.

Upvotes: 4

Related Questions