haskell - 小村庄模板中的 $forall 问题

标签 haskell yesod hamlet

我对哈姆雷特有一个奇怪的问题。我正在尝试使用 $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

最佳答案

您在模板中的缩进级别是错误的:

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

在您的版本中,该行超出了 $forall 的范围。

关于haskell - 小村庄模板中的 $forall 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7445743/

相关文章:

android - 如何在 Android 上运行 Frege 程序?

haskell - 绑定(bind)到 Haskell 数据结构内部的 monad

haskell - 如何使用 QuickCheck2 预测异常

mongodb - 选择具有 yesod 持久性的列子集

function - 调用 hamlet 文件内的函数

haskell - 如何在 Haskell 中转换 [[Char]] -> Char?

haskell - 跨多个字段的验证

rest - Haskell Yesod - 执行 POST 请求时浏览器 OPTIONS 请求的 CORS 问题

haskell - 在没有 Yesod 的情况下在 Haskell 中使用 Hamlet

haskell - 如何在 Hamlet 中使用 StaticRoute 值?