簡體   English   中英

yesod如何解決這個錯誤?

[英]yesod how to solve this error?

我剛開始使用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)

我認為,您只需postBlogR的類型簽名postBlogRHandler RepHtml 以小寫字母開頭的名稱是為類型簽名中的類型變量保留的,因此無法在此處推導出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM