The reason formlet placements (and page placements {|...|}) are allowed in page literals but not in plain XML literals is because of the way formlet validation works. Suppose there are multiple formlets, each with a separate handler, on a page. If submitting one of the formlets leads to an error then we need to re-render the entire page as XML with the error reported in the offending formlet, but all the other formlets left in tact. In order to implement this behaviour, the Page type has more structure than plain XML. Rendering a page as XML loses that structure.

The renderPage function is really an internal implementation detail that you shouldn't use directly. It is called at the last minute to render an entire page as XML. It will not necessarily do the right thing if you use it inside your own XML.

We should certainly improve the error messages for this stuff!

Sam

James Cheney wrote:
Great, that works, though it makes my head hurt a little.

I'm curious about the restriction that formlet placements have to be directly within a page (by which I guess you mean no intervening {} brackets). Could this restriction in principle be lifted (at least for simple cases like my situation where I want to make a bunch of formlets using a for loop)?

Another, related question: Assuming {| - |} brackets are meant to allow a Page to be embedded into an Xml value, why can't we do this instead:

page
<html>
<body> {
   for (x <- tbl)
    <#>{|
      page <#>{f => main}</#>
    |}</#>
   }
 </body>
</html>


This seems to have the same effect as the concatPages approach, but avoids explicitly building a list and then traversing it. But this also gives me an Undefined_recursive_module error. In fact, this happens even if I get rid of the formlet stuff and just stick some random XML inside the inner {} block. So I guess formlets were a red herring here.

Here's a smaller example demonstrating the Undefined_recursive_module error:

<foo> {| page <bar/>|}</foo>

Indeed, even doing this:

sig pageToXml : (Page) ~> Xml
fun pageToXml(p) {
 <#>{|p|}</#>
}

yields an error, this time:

*** Error: File "sugartoir.ml", line 771, characters 14-20: Assertion failed

(This is in links 0.5.0.)

But looking at the prelude, the function renderPage : (Page) ~> Xml also seems to do what I need. So maybe it would be enough to desugar <#>{|p|}</#> to renderPage(p)?

--James


_______________________________________________
links-users mailing list
[email protected]
http://lists.inf.ed.ac.uk/mailman/listinfo/links-users

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

Reply via email to