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?

smoothdeveloper
  • 1,972
  • 18
  • 19

1 Answers1

4

Your deconstruction syntax is wrong. Try this:

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

Also, your data declaration actually declares a type with one field - a tuple. If you want to declare a type with 3 fields your syntax should be different:

data Foo a = Foo a Int Int

It deconstructs more naturally:

$forall Foo a b c <- foos
    <li>#{a}
lambdas
  • 3,990
  • 2
  • 29
  • 54
  • I guess I most probably tripped on incorrect indentation but failed to bring it in the edit box. Thanks for mentionning that I might be missusing tuples instead of separate fields, that said, tuples are easier on the eye to construct (but not to deconstruct) when the values being put are expressions with more than one term Foo (something a, something b, something c) compared to Foo (something a) (something b) (something c) but I'll keep in mind the more natural way of defining those records with positional values. – smoothdeveloper Oct 03 '13 at 22:57