Die Meisterstu:cke of software engineering,
or "The crazy men in their magnificent flying
machines".
---------------------------------------------
Once again I needed to quickly write few CGI programs.
Once again I did it in C. Once again I wished I could
use some ready to go Haskell modules instead.
And again I wonder: why don't we have anything as well
designed as the Perl CGI library?
Before anyone start protesting that there are few
Haskell CGI libraries around, I will count them
quickly myself: Erik Meijer's CGI library, Sven Panne's
modification of the former (both linked from
"haskell.org"), haskell_mod - a linkable library for
Apache server, htmllib - Andy Gill's HTML library
(somehow related) and few other variations on the
same original scheme of Erik that have been privately
reported to me.
The sad truth is that numbers do not count. Quality
does! There is the Erik Meijer's paper "Server Side
Web Scripting in Haskell" (ww.cs.uu.nl/~erik/)
that has good quality engineering thoughts in it.
I would be happy to finally see those ideas
implemented, and the old libraries removed from sight.
On Oct. 4, 1999, I enquired here about availability
of software described in that paper (Where is "Server
Side Scripting" code?) and Erik's answer was, loosely
speaking, "wait until I finish it". As far as
I can tell nothing has changed in this respect.
This time I decided to do some reverse engineering
of the ideas outlined in Erik's paper. I fixed many
bugs I found there, filled in missing pieces, clarified
concepts, organized it in user friendly fashion,
documented it according to self-imposed rules
that I was arguing for a while back on this list,
and I have it ready for anyone who wishes to receive
it via email.
But I do not want to pollute the Haskell-CGI name
space by publishing it on my web pages because I
still hope to see the official Erik's version really
soon.
And here is a real explanation of the subtitle of
my message: "The crazy men in their magnificent
flying machines". Ever seen this funny movie?
I just cannot help seeing the association between
some scenes from the movie and the situation here.
Here we have two marvellous masterpieces of engineering
(well, sort of :-)): one from Erik and one from
Andy Gill, but those pieces do not easily match.
I wished the two guys would sit down and compare
the notes. The CGI library is useless without
the form support. Why not to use Andy's HTML
library for this purpose, instead of redesigning
everything from scratch? The main problem is
in definition of HTML data structures. Erik
takes a straightforward approach:
data HTML = Text String
| Element Tag [(Name, Value)] [HTML]
Andy takes a more circuitous route:
--------------------------------------------
data MarkupElement content =
= MarkupString String
| MarkupTag {
markupTag :: String,
markupAttrs :: [MarkupAttr],
markupContent :: content
}
data MarkupAttr = MarkupAttr String String
newtype Html = Html [MarkupElement Html]
---------------------------------------------
How do you propose to match those? How would
you import Andy's widgets, such as:
checkbox :: String -> String -> Html -- Andy
to use them in Erik's framework?
checkbox :: (Name, Value) -> HTML -- Erik
[Name and Value are synonims for String].
Evidently, Erik's HTML is not the same as Andy's
Html and some ugly transformation is needed here.
What a dreadful idea! Translating from Haskell
to Haskell? Something of a sort as below?
-------------------------------------------------
import qualified Html as Andy
fromMarkup :: Andy.MarkupElement Andy.Html -> HTML
fromMarkup (Andy.MarkupString str) = Text str
fromMarkup (Andy.MarkupTag
{Andy.markupTag = str,
Andy.markupAttrs = attrs,
Andy.markupContent = (Andy.Html markups)
}) =
Element str [(n, v) | (Andy.MarkupAttr n v) <- attrs]
[fromMarkup m | m <- markups]
fromHtml :: Andy.Html -> HTML
fromHtml (Andy.Html markups) =
Element "nop" [] [fromMarkup m | m <- markups]
---------------------------------------------------
/\
|| See this clutch here?
|| Can we really made one to one
transformation here?
Add to it Andy's habit of using "Html" word in all
its posiible variations: class HTML, type constructor
Html, data constructor Html, local html an htmls
variables -- and your head really starts spinning!
How about some reconcilliation between these two
modules, to make them more useful for all of us?
Jan