2013-09-22 4 views
2

Я только начал с Йесод, я следую за этот учебник: http://yannesposito.com/Scratch/en/blog/Yesod-tutorial-for-newbies/ я получаю эту ошибку:yesod как решить эту ошибку?

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

Я думаю, вам просто нужно исправить свою подпись типа для postBlogR до Handler RepHtml. Имена, начинающиеся с букв в нижнем регистре, зарезервированы для переменных типа в сигнатурах типов, поэтому их нельзя выводить прямо здесь.

+0

Это определенно проблема. 'handler' подразумевает универсальную количественную переменную типа. «Обработчик» подразумевает конкретный конкретный тип. В сообщении об ошибке объясняется, что он выводил «обработчик» из тела, что слишком специфично для универсального количественного определения. – Carl

+0

Что все сказано выше. Кроме того, в учебнике говорится, что он обновлен для работы с Yesod 1.2, и вы явно используете более старую версию, так как в ваших ошибках используется «GHandler». Это тип до 1.2. Мой совет - обновить свою установку до того, как продолжить, или, по моему мнению, вы столкнетесь с гораздо большими трудностями. – Obscaenvs

+0

Спасибо, но это не работает – arpho

Смежные вопросы