2

In Yesod, using whamletFile function in a route handler, I have issue deconstructing records in the $forall construct.

I have this data record:

data Foo a = Foo (a, Int, Int)

in hamlet template file, I itterate over an instance of [Foo] and try to use deconstructing syntax:

$forall (Foo (a, b, c)) <- foos
  <li>#{a}

it fails with this message Not in scope: 'a' while compiling

while this won't fail and would process the forall construct appropriately:

$forall (Foo (a, b, c)) <- foos
  <li>nothing special

Any idea why using deconstructing syntax would fail to bring the items in scope?

4

1 回答 1

4

您的解构语法错误。尝试这个:

$forall Foo (a, b, c) <- foos
    <li>#{a}

此外,您的数据声明实际上声明了一个具有一个字段的类型 - 一个元组。如果要声明具有 3 个字段的类型,则语法应该不同:

data Foo a = Foo a Int Int

它更自然地解构:

$forall Foo a b c <- foos
    <li>#{a}
于 2013-10-03T03:51:20.727 回答