[Ur] Simple XML Templating Problem
Burton Samograd
burton.samograd at gmail.com
Thu Oct 2 16:26:25 EDT 2014
More growing pains. I've taken my example a bit further to:
style footer
style header
fun head_tmpl (_title:string) =
<xml><head><title>{[_title]}</title></head></xml>
fun header_tmpl () : xbody = <xml><div class="header">header</div></xml>
fun footer_tmpl () : xbody = <xml><div class="footer">footer</div></xml>
fun body_tmpl (body_xml:xbody) =
<xml><body>
{header_tmpl ()}
{body_xml}
{footer_tmpl ()}
</body></xml>
fun page (title:string, body:xbody) =
<xml>
{head_tmpl title}
{body_tmpl body}
</xml>
fun main () : transaction page =
return (page "BlogMain" <xml/>)
There's a problem with the main function even with the type decleration:
urweb blog
/home/burton/blog/blog.ur:24:17: (to 24:27) Unification failure
Expression: "BlogMain"
Have con: string
Need con:
string * (xml ([Dyn = (), MakeForm = (), Body = ()]) ([]) ([]))
Incompatible constructors
Have: string
Need:
string * (xml ([Dyn = (), MakeForm = (), Body = ()]) ([]) ([]))
/home/burton/blog/blog.ur:24:12: (to 24:27) Unification failure
Expression: page "BlogMain"
Have con: xml ([Html = ()]) ([]) ([])
Need con: <UNIF:U344::Type> -> <UNIF:U345::Type>
Incompatible constructors
Have: xml ([Html = ()]) ([]) ([])
Need: <UNIF:U344::Type> -> <UNIF:U345::Type>
Still learning the basics but I think once I get over the learning curve
things will go a quite a bit smoother.
--
Burton Samograd
On Thu, Oct 2, 2014 at 1:56 PM, Sergey Mironov <grrwlf at gmail.com> wrote:
> 2014-10-02 23:33 GMT+04:00 Burton Samograd <burton.samograd at gmail.com>:
> > Still no luck:
> >
> > fun head_template (_title:string) =
> > return <xml><head><title>{[_title]}</title></head></xml>
> >
> > fun main () = return <xml>
> > {head_template "Blog Main"}
> > <body>
> > </body>
> > </xml>
>
> The error is caused by the type mismatch. <xml>{f x}</xml> works only
> for pure functions f. Pure functions usually don't mention
> 'transaction' in their type signatures, nor they use 'return' keyword
> in their bodies. Your code snippet have two problems: 1) unspecified
> type for [main] and 2) 'return' keyword in [head_template] conflicting
> with <xml>{..}</xml> call. Try this code instead:
>
> fun head_template (_title:string) =
> <xml><head><title>{[_title]}</title></head></xml>
>
> fun main () : transaction page = return <xml>
> {head_template "Blog Main"}
> <body>
> </body>
> </xml>
>
> Regards,
> Sergey
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20141002/c30d80a2/attachment.html>
More information about the Ur
mailing list