首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >hamlet模板中的$forall出现问题

hamlet模板中的$forall出现问题
EN

Stack Overflow用户
提问于 2011-09-16 21:52:55
回答 1查看 893关注 0票数 5

我和哈姆雷特有个奇怪的问题。我试图使用$forall来迭代一个列表,但是我总是得到一个“不在作用域”的错误。我在Win7上运行yesod 0.9.2.2。

抛开糟糕的设计不谈,有人知道我哪里错了吗?删除"db“的变量插值可以很好地执行。

相关的哈姆雷特:

代码语言:javascript
复制
 !!!
<h1> Database List
<hr>
<table>

  <tr>
       <td> Host
       <td> Status
  $forall db <- dbList
  <tr>
       <td> #{host db}

相关的处理程序代码:

代码语言:javascript
复制
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时遇到这个错误:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-16 22:47:37

模板中的缩进级别错误:

代码语言:javascript
复制
$forall db <- dbList
    <tr>
        <td>#{host db}

在您的版本中,行超出了$forall的作用域。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7445743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档