1
我試圖讓博客示例運行,但在某些處理函數中存在類型問題,我不知道如何解決該問題。無法與yesod博客示例中的預期類型相匹配
我試圖運行在此發佈的例子: Yesod blog example 我改變一點點,我添加類型defaultLayout功能,並使其耶索德的實例來擺脫雙重定義。
defLayout :: GWidget a Blog() -> GHandler a Blog RepHtml
defLayout inside = do
mmsg <- getMessage
pc <- widgetToPageContent $ do
toWidget [lucius|
body {
width: 760px;
margin: 1em auto;
font-family: sans-serif;
}
textarea {
width: 400px;
height: 200px;
}
#message {
color: #900;
}
|]
inside
hamletToRepHtml [hamlet|
$doctype 5
<html>
<head>
<title>#{pageTitle pc}
^{pageHead pc}
<body>
$maybe msg <- mmsg
<div #message>#{msg}
^{pageBody pc}
|]
instance Yesod Blog where
approot = ApprootStatic "http://localhost:3000"
defaultLayout = defLayout
這些是給我的問題的功能:
getBlogR :: Handler RepHtml
getBlogR = do
muser <- maybeAuth
entries <- runDB $ selectList [] [Desc EntryPosted]
((_, entryWidget), enctype) <- generateFormPost entryForm
defaultLayout $ do
setTitleI MsgBlogArchiveTitle
[whamlet|
$if null entries
<p>_{MsgNoEntries}
$else
<ul>
$forall Entity entryId entry <- entries
<li>
<a [email protected]{EntryR entryId}>#{entryTitle entry}
$maybe Entity _ user <- muser
$if isAdmin user
<form method=post enctype=#{enctype}>
^{entryWidget}
<div>
<input type=submit value=_{MsgNewEntry}>
$nothing
<p>
<a [email protected]{AuthR LoginR}>_{MsgLoginToPost}
|]
getEntryR :: EntryId -> Handler RepHtml
getEntryR entryId = do
(entry, comments) <- runDB $ do
entry <- get404 entryId
comments <- selectList [] [Asc CommentPosted]
return (entry, map entityVal comments)
muser <- maybeAuth
((_, commentWidget), enctype) <- generateFormPost (commentForm entryId)
defaultLayout $ do
setTitleI $ MsgEntryTitle $ entryTitle entry
[whamlet|
<h1>#{entryTitle entry}
<article>#{entryContent entry}
<section .comments>
<h1>_{MsgCommentsHeading}
$if null comments
<p>_{MsgNoComments}
$else
$forall Comment _entry posted _user name text <- comments
<div .comment>
<span .by>#{name}
<span .at>#{show posted}
<div .content>#{text}
<section>
<h1>_{MsgAddCommentHeading}
$maybe _ <- muser
<form method=post enctype=#{enctype}>
^{commentWidget}
<div>
<input type=submit value=_{MsgAddCommentButton}>
$nothing
<p>
<a [email protected]{AuthR LoginR}>_{MsgLoginToComment}
|]
這裏的輸出我得到的,當我嘗試運行它:
blog.hs:147:4:
Couldn't match expected type `GWidget Blog Blog()'
with actual type `(t0, t1)'
In the pattern: (_, entryWidget)
In the pattern: ((_, entryWidget), enctype)
In a stmt of a 'do' block:
((_, entryWidget), enctype) <- generateFormPost entryForm
blog.hs:202:4:
Couldn't match expected type `GWidget Blog Blog()'
with actual type `(t0, t1)'
In the pattern: (_, commentWidget)
In the pattern: ((_, commentWidget), enctype)
In a stmt of a 'do' block:
((_, commentWidget), enctype) <- generateFormPost
(commentForm entryId)
謝謝你,那是做的。沒有意識到類型已經改變。 – Altair 2012-08-07 13:24:41