[Haskell-cafe] Rethinking OO idioms
jgoerzen at complete.org
Wed Sep 29 16:29:47 EDT 2004
I've worked with languages with object-oriented features for awhile now.
Python and OCaml, the two with which I work the most, both have OO.
One of my first projects in Haskell would be to write a Haskell version
of Python's ConfigParser class. I wrote, a version of this for
OCaml that works very well.
In a nutshell, ConfigParser is a utility for working with sectioned
configuration files in a style similar to the familiar .ini files from
Windows. It has methods to read a configuration file, get/set the items
that are being configured, and write a new file back out. This, then,
is a fairly typical metaphor for OO programs: an instance of a class has
some state that can be accessed or modified, and possibly stored and
So I am thinking about a ConfigParser for Haskell. The first thing that
occured to me is that Haskell has no OO features, so I'm not sure what
is the best way to handle the "class" and its various methods.
The next thing that occured to me is that, unlike OCaml and Python
classes, Haskell has no mutable variables. A call like
config.setOption("main", "initpath", "/usr") in Python -- which alters
the state of the config object and returns nothing -- would be
impossible in Haskell (unless perhaps the FiniteMaps are mutable
I guess I'm having trouble translating this common OO language paradigm
into the Haskell world.
Thanks for any insight.
BTW, if I get a working ConfigParser for Haskell, I will publish it
under the GPL like all the rest of my code.
More information about the Haskell-Cafe