[Haskell-cafe] Rethinking OO idioms

Ben.Yu at combined.com Ben.Yu at combined.com
Wed Sep 29 17:07:45 EDT 2004


You can use state monad to mimic mutation.
Also, take a look at the recursive decent monadic parsec library. It may
have done what you are trying to do.

Regards,

Ben.


                                                                                                                                           
                      John Goerzen                                                                                                         
                      <jgoerzen at complete.or        To:       haskell-cafe at haskell.org                                                      
                      g>                           cc:                                                                                     
                      Sent by:                     Subject:  [Haskell-cafe] Rethinking OO idioms                                           
                      haskell-cafe-bounces@                                                                                                
                      haskell.org                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      09/29/2004 03:29 PM                                                                                                  
                                                                                                                                           




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[1] class.  I wrote[2],[3] 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
retrieved.

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
somehow?)

I guess I'm having trouble translating this common OO language paradigm
into the Haskell world.

Thanks for any insight.

-- John

BTW, if I get a working ConfigParser for Haskell, I will publish it
under the GPL like all the rest of my code.

[1] http://www.python.org/doc/current/lib/RawConfigParser-objects.html
[2] http://gopher.quux.org:70/devel/missinglib/html/ConfigParser.html
[3]
http://gopher.quux.org:70/devel/missinglib/html/ConfigParser.rawConfigParser.html



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe




This message is intended only for the addressee and may contain information
that is confidential or privileged. Unauthorized use is strictly prohibited
and may be unlawful. If you are not the intended recipient, or the person
responsible for delivering to the intended recipient, you should not read,
copy, disclose or otherwise use this message, except for the purpose of
delivery to the addressee. If you have received this email in error, please
delete and advise the IT Security department at ITSEC at combined.com
immediately



More information about the Haskell-Cafe mailing list