我和哈姆雷特有一个奇怪的问题。我正在尝试使用$ forall迭代列表,但我不断收到“不在范围内”错误。我在Win7上运行yesod 0.9.2.2。
除了可怕的设计,任何人都知道我哪里出错了?删除“db”的变量插值可以让执行正常。
相关的小村庄:
!!!
<h1> Database List
<hr>
<table>
<tr>
<td> Host
<td> Status
$forall db <- dbList
<tr>
<td> #{host db}
相关的处理程序代码:
data Database = Database {dbType :: DBType,
host :: String,
user :: String,
password :: String
}
dbList = [Database Oracle "cpalmerws" "system" "***",
Database Oracle "bdblnx" "system" "***",
Database Postgres "localhost" "postgres" "***"]
getDBStatusR :: Handler RepHtml
getDBStatusR = do
mu <- maybeAuth
defaultLayout $ do
setTitle "DB Status Page"
addWidget $(widgetFile "dbstatus")
运行yesod devel时出现此错误:
Handler\DBStatus.hs:47:17:
Not in scope: `db'
In the result of the splice:
$(widgetFile "dbstatus")
To see what the splice expanded to, use -ddump-splices
In the first argument of `addWidget', namely
`$(widgetFile "dbstatus")'
In the expression: addWidget ($(widgetFile "dbstatus"))
Starting development server...
dist\devel.hs:3:1:
Failed to load interface for `Application':
it is not a module in the current program, or in any known package.
Exit code: ExitFailure 1
答案 0 :(得分:8)
模板中的缩进级别错误:
$forall db <- dbList
<tr>
<td>#{host db}
在您的版本中,该行不在$ forall的范围内。