Statically typed XHTML?

12 views
Skip to first unread message

Anton Tayanovskyy

unread,
Sep 27, 2011, 6:25:31 PM9/27/11
to WebSharper
Hi,

I have done a few experiments to get static (typesystem-level)
verification of constructed XHTML using the XHTML strict schema.
Unfortunately it looks impossible to superimpose this on the current
WebSharper-style syntax that looks like `Div [Text "foo"]`. What I
came up with instead is a method I have seen used by Java and C#, the
so-called `fluent` style. The advantage here is that the return type
of the method can be custom. The current type is analogous to a parser
state and available methods to state transitions. This formalism is
powerful enough to express most XHtml restrictions statically, so that
most well-typed code validates (exceptions are some constraints on
attribute values, for example).

Here is how a template definition might look like using this syntax:

let template body =
Html
.Head.Title("Home Page").End
.Body
.Div.Embed(body).End
.End

Perhaps a little beastly to the eye, but it gets the job done of
checking validity at compile time.

Would anyone be interested in having this library available? Are there
working solutions like this in C# land anyone has used?

Thanks,


Anton

Ryan Riley

unread,
Oct 31, 2011, 1:28:53 PM10/31/11
to websh...@googlegroups.com
I don't know if it performs static verification, but Wing Beats is pretty similar.

Ryan Riley

unread,
Oct 31, 2011, 1:30:54 PM10/31/11
to websh...@googlegroups.com
Eh, on second thought, Wing Beats has more in common with the existing syntax.

I think this library would be very useful, especially if it can also deserialize XHTML into a source code representation.

What about (X)HTML5?

Anton Tayanovskyy

unread,
Nov 1, 2011, 3:25:56 PM11/1/11
to websh...@googlegroups.com

Well, with some compromises HTML5 sounds feasible. My only concern is
maintaining such a library. In the ideal world I would have an
automated system that generates the library from a formal HTML
specification. Then ideally changes to the specification require a
simple rebuild. Unfortunately, looking at HTML 5 draft [1] I don't
really see a schema-like description that could be consumed by a
machine..

For this purpose XHTML wins by having a schema.

I have looked at WingBeats but have not figured out how much
validation if any does it do statically. Would be interesting to know.
Of course performing dynamic validation is a no-brainer, just using
the .NET schema validation code..

[1] http://www.w3.org/TR/html5/


--
Kind Regards,
Anton Tayanovskyy

WebSharper™ - type-safe JavaScript in F#
http://intellifactory.com

Reply all
Reply to author
Forward
0 new messages