Jon Fairbairn | 18 Dec 18:36
X-Face
Favicon

Announcement: Typeful [x]html combinators -- pre-release 0

... or,  "whoops! I've writtten another html combinator library."

History: I was surprised to find that all the Haskell html
generating stuff I've tried allowed one to construct invalid
HTML. I thought to myself that this might make an
undergraduate project, but then I thought "maybe it's too
hard? I'd better write some of it to see how hard it is."
After a while I decided that it was probably a bit too big
for an undergraduate project, but by that time I'd written
too much of it to throw away, and just had to keep going so
here it is.

I'm announcing it here because I hope the audience is fairly
small but discerning, and I'm announcing it at all because
I've run out of steam for the moment. This is the first code
above the size of a nonce-programme that I've written since
I got ill years ago, so don't go too hard on me! I still am
ill, so don't expect swift responses either. I'm mainly
interested in opinions on the questions below, and in test
cases that fail validation.

You can get it with 

darcs get --partial http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/HTMLs

and the documentation (such as it is) is at 

<http://homepage.ntlworld.com/jon.fairbairn/Typeful/Text/HTMLs/Documentation/haddock/>

Here's the announcement (which might better be called the
(Continue reading)

Yitzchak Gale | 19 Dec 09:31

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Jon Fairbairn wrote:
> ... or,  "whoops! I've writtten another html combinator library."
> History: I was surprised to find that all the Haskell html
> generating stuff I've tried allowed one to construct invalid
> HTML...

This is a wonderful idea, and it is clear that you have
done some serious work here.

> I'm announcing it here because I hope the audience is fairly
> small but discerning

I believe that the audience could be large. As for discerning,
that remains to be seen. :)

What you are doing here is enforcing a DTD using
the Haskell type system. Apart from your plans for
HTML 4.01, perhaps a better generalization would
be to generate typeful combinators that could
validate at compile time for any given XML DTD.

That would be hard. But now that you have fully
worked out the first special case, a good chunk
of the work has already been done.

Regards,
Yitz
Jon Fairbairn | 19 Dec 16:06
X-Face
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

"Yitzchak Gale" <gale <at> sefer.org> writes:

> Jon Fairbairn wrote:
>> ... or,  "whoops! I've writtten another html combinator library."
>> History: I was surprised to find that all the Haskell html
>> generating stuff I've tried allowed one to construct invalid
>> HTML...
>
> This is a wonderful idea, and it is clear that you have
> done some serious work here.

Thanks. It certainly felt that way... in case anyone reading
my announcement thought otherwise, the library is pretty
much complete, but there are a few design decisions that
need more heads than just my own. [I've thought of another
one: should I group together the prohibited elements
corresponding to %pre.exclusion, %formctrl (in the html dtd)
to reduce the number of type arguments?]

>> I'm announcing it here because I hope the audience is fairly
>> small but discerning
>
> I believe that the audience could be large. As for discerning,
> that remains to be seen. :)

:-) Well, I mean here on the libraries list. If I get some
feedback from here I'll announce it on one of the other
Haskell lists.

> What you are doing here is enforcing a DTD using
(Continue reading)

Mattias Bengtsson | 7 Jan 15:57
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

On Wed, 2007-12-19 at 15:06 +0000, Jon Fairbairn wrote:
> "Yitzchak Gale" <gale <at> sefer.org> writes:
> > What you are doing here is enforcing a DTD using
> > the Haskell type system. Apart from your plans for
> > HTML 4.01, perhaps a better generalization would
> > be to generate typeful combinators that could
> > validate at compile time for any given XML DTD.
> 
> I think that would be the job of something like HaXml or
> HXT, and there are plenty of good people working on them.
> To clarify, what these types enforce is something stronger
> than an XML DTD, more like the SGML DTD of html (and as I
> write this I am inclining myself further towards making the
> document tree types fit the common subset); it enforces the
> restrictions that are only expressed in prose in the
> xhtml1.0 standard. You could think of it as enforcing a
> schema (that the w3c didn't provide).

It seems that they did actually[1]. 
Making a program for generating ADT's and combinators from XML schemas
to provide type safe XML is something i'd very much like to do someday.
One thing i'm uncertain of is whether supporting namespaces would be a
problem or not. It would be a shame to have a bunch of generated
XML-standards in Haskell that can't be used together (ie. embedding
MathML or SVG in XHTML).

Mattias

1: http://www.w3.org/TR/xhtml1-schema/
(Continue reading)

Jon Fairbairn | 8 Jan 11:31
X-Face
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Mattias Bengtsson <moonlite <at> dtek.chalmers.se> writes:

> On Wed, 2007-12-19 at 15:06 +0000, Jon Fairbairn wrote:
>> I think that would be the job of something like HaXml or
>> HXT, and there are plenty of good people working on them.
>> To clarify, what these types enforce is something stronger
>> than an XML DTD, more like the SGML DTD of html (and as I
>> write this I am inclining myself further towards making the
>> document tree types fit the common subset); it enforces the
>> restrictions that are only expressed in prose in the
>> xhtml1.0 standard. You could think of it as enforcing a
>> schema (that the w3c didn't provide).
>
> It seems that they did actually[1]. 

Thanks for finding that (I do hate the way that the W3C
issues proper formal definitions of things but makes the
informal one the normative one); I can use it to check
attribute types and so on. Does it enforce the nesting
restrictions (described in app. B of the xhtml1 dtd)?
Looking through it with little knowledge of schemas, I can't
see that it does.

> Making a program for generating ADT's and combinators from XML schemas
> to provide type safe XML is something i'd very much like to do someday.

It would be a good thing to do, though not something I'm
thinking of just now (a bit too much for me at the moment).

> One thing i'm uncertain of is whether supporting namespaces would be a
(Continue reading)

Mattias Bengtsson | 8 Jan 12:14
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

On Tue, 2008-01-08 at 10:31 +0000, Jon Fairbairn wrote:
> Thanks for finding that (I do hate the way that the W3C
> issues proper formal definitions of things but makes the
> informal one the normative one); I can use it to check
> attribute types and so on. Does it enforce the nesting
> restrictions (described in app. B of the xhtml1 dtd)?
> Looking through it with little knowledge of schemas, I can't
> see that it does.

Yes this is really frustrating. 
I think the schema is supposed to enforce nesting restrictions. At least
that's how i interpret paragraph 1.3[1] in the Note. It doesn't seem to
be able to enforce everything though (eg. the legend example in 1.3).

> > Making a program for generating ADT's and combinators from XML schemas
> > to provide type safe XML is something i'd very much like to do someday.
> 
> It would be a good thing to do, though not something I'm
> thinking of just now (a bit too much for me at the moment).

Same here i think. It's on my TODO though. :)

Mattias

1: http://www.w3.org/TR/xhtml1-schema/#why
Jon Fairbairn | 8 Jan 17:32
X-Face
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Mattias Bengtsson <moonlite <at> dtek.chalmers.se> writes:

> On Tue, 2008-01-08 at 10:31 +0000, Jon Fairbairn wrote:
>> Thanks for finding that (I do hate the way that the W3C
>> issues proper formal definitions of things but makes the
>> informal one the normative one); [...]
>
> Yes this is really frustrating. 

Indeed!

> I think the schema is supposed to enforce nesting restrictions. At least
> that's how i interpret paragraph 1.3[1] in the Note. It doesn't seem to
> be able to enforce everything though (eg. the legend example in 1.3).

You may be right. The schema is not the easiest thing in the
world to read (whoever said that it was strange how people
who complained for years that lisp had too many brackets now
endorse XML had it right), but I think the "content model
for exclusions" parts cover this.

--

-- 
Jón Fairbairn                                 Jon.Fairbairn <at> cl.cam.ac.uk
Ketil Malde | 9 Jan 20:52

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Mattias Bengtsson <moonlite <at> dtek.chalmers.se> writes:

> Making a program for generating ADT's and combinators from XML schemas
> to provide type safe XML is something i'd very much like to do someday.
> One thing i'm uncertain of is whether supporting namespaces would be a
> problem or not. It would be a shame to have a bunch of generated
> XML-standards in Haskell that can't be used together (ie. embedding
> MathML or SVG in XHTML).

How /can/ one check validity of namespace-using XML?  Do you have a
separate DTD (or Schema, if you think DTDs are too easy to read) for
each namespace?  If so, how do you specify where foreign namespaces
are legal?  If the top-level DTD specifies -- and thus needs to know,
in advance, the details about -- the sub-namespaces, then what's the
point of namespaces at all? 

I'm confused.

-k
--

-- 
If I haven't seen further, it is by standing in the footprints of giants
Mattias Bengtsson | 10 Jan 00:49
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

On Wed, 2008-01-09 at 20:52 +0100, Ketil Malde wrote: 
> How /can/ one check validity of namespace-using XML?  Do you have a
> separate DTD (or Schema, if you think DTDs are too easy to read) for
> each namespace?  

I'm not 100% sure but i believe so yes. 
XML Schemas enforces more properties than a DTD and are hence of more
value (to me at least).

> If so, how do you specify where foreign namespaces
> are legal?  If the top-level DTD specifies -- and thus needs to know,
> in advance, the details about -- the sub-namespaces, then what's the
> point of namespaces at all? 

This is exactly what i'm also having trouble understanding. Need to read
more!

> I'm confused.

So am i. :)

Mattias
_______________________________________________
Libraries mailing list
Libraries <at> haskell.org
http://www.haskell.org/mailman/listinfo/libraries
Ketil Malde | 10 Jan 10:05

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Mattias Bengtsson <moonlite <at> dtek.chalmers.se> writes:

>> If so, how do you specify where foreign namespaces
>> are legal?  If the top-level DTD specifies -- and thus needs to know,
>> in advance, the details about -- the sub-namespaces, then what's the
>> point of namespaces at all? 

> This is exactly what i'm also having trouble understanding. Need to read
> more!

>> I'm confused.

> So am i. :)

Well - I just found some links.  A schema can contain import
statements, basically #include'ing other schemas:

  http://lists.xml.org/archives/xml-dev/200211/msg00880.html

For DTD's, I think you'd have to write the DTD to use the prefix
(I forget the proper name for it) and the local name - but I've lost
the link that said so.

So for both Schema and DTD validation, you'd need to know in advance
all the tags you'd like to use, but Schema lets you more easily reuse
'chunks' of the document definition (or XML grammar).

Stray thought:

I'm currently working on a storage for various data types.  Due to the
(Continue reading)

Yitzchak Gale | 10 Jan 13:17

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Ketil Malde wrote:
>>> If so, how do you specify where foreign namespaces
>>> are legal?  If the top-level DTD specifies -- and thus needs to know,
>>> in advance, the details about -- the sub-namespaces, then what's the
>>> point of namespaces at all?
> Well - I just found some links.  A schema can contain import
> statements, basically #include'ing other schemas:
>   http://lists.xml.org/archives/xml-dev/200211/msg00880.html
> ...So for both Schema and DTD validation, you'd need to know in advance
> all the tags you'd like to use,

You can combine them using Schematron:

http://www.schematron.com/overview.html

It even allows you to mix validation languages,
e.g., DTD, XML Schema, Relax NG, etc.

-Yitz
Tomasz Zielonka | 8 Jan 14:15

Re: Announcement: Typeful [x]html combinators -- pre-release 0

On Tue, Dec 18, 2007 at 05:38:47PM +0000, Jon Fairbairn wrote:
> ... or,  "whoops! I've writtten another html combinator library."
> 
> History: I was surprised to find that all the Haskell html
> generating stuff I've tried allowed one to construct invalid
> HTML.

Did you take a look at Peter Thiemann's WASH/HTML? It contains a monadic
combinator library that checks proper nesting of HTML tags at compile
time. The library also has an unchecked version, and the checked
version doesn't seem to be used too often, even by the author himself.
Last time I checked it still lacked the obvious rule to allow putting
BODY in HTML, and I had to define that instance myself. But this is only
a small wart, and the library proved to be quite useful for me.

> I'm announcing it here because I hope the audience is fairly
> small but discerning, and I'm announcing it at all because
> I've run out of steam for the moment. This is the first code
> above the size of a nonce-programme that I've written since
> I got ill years ago, so don't go too hard on me!

I hope you won't consider my response hard ;-)
Perhaps you could borrow some ideas from Peter's code, or vice versa.

Best regards
Tomasz
Jon Fairbairn | 8 Jan 15:43
X-Face
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Tomasz Zielonka <tomasz.zielonka <at> gmail.com> writes:

> On Tue, Dec 18, 2007 at 05:38:47PM +0000, Jon Fairbairn wrote:
>> ... or,  "whoops! I've writtten another html combinator library."
>> 
>> History: I was surprised to find that all the Haskell html
>> generating stuff I've tried allowed one to construct invalid
>> HTML.
>
> Did you take a look at Peter Thiemann's WASH/HTML?

I did.

> It contains a monadic combinator library that checks
> proper nesting of HTML tags at compile time. The library
> also has an unchecked version,

It's possible that I only tried the unchecked version: I
just thought of an invalid example, read what documentation
I could find and generated some invalid html. However,
Thiemann's thesis says

   The current library implements neither inclusions nor
   exceptions.

So I hope I might be forgiven if I overlooked a difference
between the distribution and the thesis! Does the checked
version now enforce appendix B and prevent <a> appearing
anywhere within <a> and so on?

(Continue reading)

Tomasz Zielonka | 10 Jan 13:21

Re: Announcement: Typeful [x]html combinators -- pre-release 0

On Tue, Jan 08, 2008 at 02:43:08PM +0000, Jon Fairbairn wrote:
> > It contains a monadic combinator library that checks
> > proper nesting of HTML tags at compile time. The library
> > also has an unchecked version,
> 
> It's possible that I only tried the unchecked version: I
> just thought of an invalid example, read what documentation
> I could find and generated some invalid html.

That's an easy trap to fall into, especially because the author seems to
use only unchecked combinators in examples ;-)

> However,
> Thiemann's thesis says
> 
>    The current library implements neither inclusions nor
>    exceptions.
> 
> So I hope I might be forgiven if I overlooked a difference
> between the distribution and the thesis! Does the checked
> version now enforce appendix B and prevent <a> appearing
> anywhere within <a> and so on?

I am not familiar with the HTML standards enough to understand
everything you say here, but I've just checked that you can't put <a>
inside <a> using the checked combinators. But I can't say if it
checks everything your library checks.

> Another difference is that I haven't used any non-Haskell 98
> constructs other than using Template Haskell to generate
(Continue reading)

Jon Fairbairn | 10 Jan 20:01
X-Face
Favicon

Re: Announcement: Typeful [x]html combinators -- pre-release 0

Tomasz Zielonka <tomasz.zielonka <at> gmail.com> writes:

> On Tue, Jan 08, 2008 at 02:43:08PM +0000, Jon Fairbairn wrote:
>> > It contains a monadic combinator library that checks
>> > proper nesting of HTML tags at compile time. The library
>> > also has an unchecked version,
>> 
>> It's possible that I only tried the unchecked version: I
>> just thought of an invalid example, read what documentation
>> I could find and generated some invalid html.
>
> That's an easy trap to fall into, especially because the author seems to
> use only unchecked combinators in examples ;-)

That's a bit of a strange thing to do.  Having gone to the
trouble of setting things up so that it can check (some
degree of) validity, why not use it? Isn't this what Haskell
is about?

Exploring WaSH isn't made easy by the documentation; if I try 

   build_document (html (head (title (text "foo"))
                   ## (body (h1 (text "foo")))))

-- essentially the first example from the pdf of the paper
"A Typed Representation for HTML and XML documents in
Haskell" -- I get 

<interactive>:1:16:
    No instance for (AddTo HTML HTML)
(Continue reading)


Gmane