2

我刚开始使用 Yesod,我正在关注本教程:http: //yannesposito.com/Scratch/en/blog/Yesod-tutorial-for-newbies/ 我收到此错误:

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 { ... } }

这是我的 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")

我的路线:

    /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

和我的模型:

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

1 回答 1

4

我认为,您只需将类型签名修复为postBlogRto Handler RepHtml。以小写字母开头的名称是为类型签名中的类型变量保留的,因此这里不能推导出来。

于 2013-09-22T19:21:17.097 回答