[Haskell-cafe] Language Workbenches - the Haskell solution?

Yitzchak Gale gale at sefer.org
Mon Sep 12 07:10:31 EDT 2005


Ralf Lammel wrote:

>> XML... I wonder whether they discuss it...

yoann padioleau wrote:

> Yes, fowler mentionned XML: "XML has its uses,
> but isn't exactly easy to read..."  I dont think
> XML is a good idea for files that are
> managed/edited by humans.

It can be very human readable if set up properly.

I once set up a configurations system like that
for a large C++ app. The config files are very
readable, and easy to edit using widely available
free XML editors. For example, in the
configuration file you have things like:

<Age>25</Age>
<Gender>F</Gender>
<Location>
  <City>Cleveland</City>
  <State>Ohio</State>
</Location>

etc.

With the source code, there is a master XML
document that sets up the fields:

<data name="Age" type="Int"/>
<data name="Gender" type="enum">
  <choice>F</choice>
  <choice>M</choice>
</data>
<category name="Location">
  <data name="City" type="String"/>
  <data name="State" type="String"/
</category>

and then you can access the fields in the C++ code
as Config.Age, Config.Location.City,
Config.Location.State, etc., with the proper type.
The configuration file is verified and
type-checked at run time.  To add trees and
fields, you just edit the master XML and type
make.

If you want a GUI for configuration, you could,
for example, write a fairly simple transformation
of the master XML into a .NET dialog, or glade
file for GTK, or whatever. We never did that,
though.

It took some time to set up, but it works great.
My developers and my users loved it. It was done
for a company, so I can't release the code, but
you get the idea. You could obviously do the same
thing easily in Haskell, probably with less work.

Of course, the portablity of XML is illusory. This
is my own proprietary usage of XML, so you would
still need to write the code to support it in any
given language. (I didn't use "standards" like
DTD, XML Schema, etc., for the very reason
mentioned - human readability was a requirement.)
The result would be just as portable if you used
any other simple syntax - based on Python,
Haskell, or anything else.

If you want Haskell syntax, another idea might be
to use Haskell's built-in Haskell parser. As long
as you limit yourself to simple syntax, it would
be easy enough to process the resulting syntax
tree.

Another approach which IS portable, though in a
different sense, is to write the configuration
file in N3. That is very human readable, and then
at least some of the information in the
configuration file might be usable in a meaningful
way by other applications.

Regards,
Yitz


More information about the Haskell-Cafe mailing list