tyxml icon indicating copy to clipboard operation
tyxml copied to clipboard

Composability issues with the ppx

Open Drup opened this issue 8 years ago • 5 comments

Here is an example of something that doesn't work:

let mytitle = [%html5 "<title>A Fabulous Web Page</title>" ]

let mypage = [%html5
  "<html>
    <head>"mytitle"</head>
    <body></body>"
]

Error message by markup: "head element must have exactly one title child element".

I don't know how solvable it is. It sounds tricky.

Drup avatar Apr 02 '16 13:04 Drup

Well, this isn't really due to the PPX primarily – it is due to irregularities in the TyXML interface. However, the PPX might have an opportunity to hackily coerce its way through such situations, due to having some reflection available. It does seem a bit complicated, since we would want the coercion to be compile-time for best effect.

aantron avatar Apr 02 '16 14:04 aantron

I don't see how you would do anything about it in a composable way. Consider:

let mytitle = [%html5 "<title>A Fabulous Web Page</title>" ]

let myhead = [%html5
  "<head>"mytitle"<meta bla/>"mytitle"</head>"
]

You need name resolution and typechecking to know that this is incorrect. You couldn't even generate tyxml code for that, without typechecking. This is precisely why tyxml is irregular there.

It's not a big problem in practice, though, you can just inline the title tag and use the antiquotation on the pcdata.

Drup avatar Apr 02 '16 14:04 Drup

Yes, I think making this fully composable without inserting run-time coercions isn't going to happen with a PPX.

aantron avatar Apr 02 '16 15:04 aantron

I think this should be made to work, if possible, since you made the change to how antiquotations are inserted:

let%html to_ocaml = "<li><a href='ocaml.org'>OCaml</a></li>"
let%html to_tyxml = "<li><a href='ocsigen.org/tyxml'>TyXML</a></li>"
let%html links = "<ul>" to_ocaml "<li>foo</li>" to_tyxml "</ul>"

Looking into it.

aantron avatar Apr 22 '16 15:04 aantron

Ok,

let%html links = "<ul>" [to_ocaml] "<li>foo</li>" [to_tyxml] "</ul>"

aantron avatar Apr 22 '16 16:04 aantron