Re: [Haskell-cafe] Rethinking OO idioms

2004-10-04 Thread Mike Burns
--- John Goerzen mumbled on 2004-09-29 20.29.47 + ---
> 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?)  

http://www.ccs.neu.edu/home/matthias/Presentations/ecoop2004.pdf

Mutation is not very OO-like.

-- 
Mike Burns [EMAIL PROTECTED] http://mike-burns.com
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rethinking OO idioms

2004-10-04 Thread Mikael Brockman
John Goerzen <[EMAIL PROTECTED]> writes:

> 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.

I would expect these signatures:

| module Configuration where
|
| type Key = String
| type Value = String
| type Configuration = FiniteMap Key Value
|
| read   :: FileName -> IO Configuration
| write  :: FileName -> Configuration -> IO ()
| update :: Configuration -> Key -> Value -> IO ()
| lookup :: Configuration -> Key -> Value

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

The purest approach is to have every configurable function accept a
Configuration.  Functions that in Python would alter the dictionary
would simply return a new one.

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rethinking OO idioms

2004-09-30 Thread John Goerzen
On Thursday 30 September 2004 07:54 am, Jeremy Jones wrote:
> John (and Haskell community),
>
> I just subscribed to the Haskell mailing list the other day and this
> posting grabbed my attention.  I've been workin with Python for a few
> years now and have recently decided to try to expand my horizons to
> Haskell (and OCaml).  I love Python, but I feel like I could learn a
> lot that could be applied to Python from understanding FP languages
> like Haskell (and OCaml).  That being said, can you point me to any

One of the interesting things about Python is that it has slowly been 
adding functional programming mechanisms to the language.  Some of the 
constructs we all love in FP are available on Python.  For instance:

 * anonymous functions ("lambda" keyword)

 * nested scopes and the ability to return functions

 * iterable objects

On the other hand, Python's typing system is nowhere near as powerful as 
that of Haskell or OCaml.  OCaml, and to an even larger extent, 
Haskell, have a wonderful typing system: it's strong, yet it 
inobtrusive.  I am a fan of that, and it helps these languages scale to 
large projects better than Python -- while at the same time keeping 
them suitable for small ones (unlike, say, Java)

OCaml has an object system.  It's not as powerful as Python's in most 
respects, and can be loosely described as a functional hybrid of the 
Python and Java object systems 

I find myself writing most of my new code in OCaml these days.  If I can 
manage to get a Haskell compiler built on AIX, I may move to 
Haskell :-)

(Building anything on that platform is difficult, sigh)

> documentation online or books that are more suited to a Python person
> trying to understand Haskell (and OCaml)?  Any help is appreciated.

This is a great resource:  Learning OCaml for C, C++, Perl, and Java 
programmers:

http://www.merjis.com/developers/ocaml_tutorial/

I wish something like that existed for Haskell.  I may write one 
someday. :-)

Once you know OCaml, though, Haskell will come a lot easier.  The typing 
systems are quite similar, as are many of the concepts.  I/O is very 
different though.  Haskell I/O is different from anything else I've 
ever seen, so I can't really come up with a good analogy for you 
there :-)

This is a good Haskell tutorial: http://www.isi.edu/~hdaume/htut/
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rethinking OO idioms

2004-09-30 Thread Jeremy Jones
John (and Haskell community),
I just subscribed to the Haskell mailing list the other day and this 
posting grabbed my attention.  I've been workin with Python for a few 
years now and have recently decided to try to expand my horizons to 
Haskell (and OCaml).  I love Python, but I feel like I could learn a lot 
that could be applied to Python from understanding FP languages like 
Haskell (and OCaml).  That being said, can you point me to any 
documentation online or books that are more suited to a Python person 
trying to understand Haskell (and OCaml)?  Any help is appreciated.

Jeremy Jones

John Goerzen wrote:
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
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe
 

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Simple example using Parsec (was: [Haskell-cafe] Rethinking OO idioms)

2004-09-30 Thread Graham Klyne
At 09:01 30/09/04 +0100, Bayley, Alistair wrote:
Ben suggested using Parsec for reading the config file. Parsec is a fine
library, but there is a learning curve, and you might find it quicker to do
the parsing yourself, if it's very simple. Your call.
Hmmm... Parsec *can* be simple too.  Here's one I did earlier:
  http://www.ninebynine.org/Software/HaskellUtils/RegexParser.hs
#g

Graham Klyne
For email:
http://www.ninebynine.org/#Contact
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rethinking OO idioms

2004-09-30 Thread David Roundy
On Wed, Sep 29, 2004 at 08:29:47PM +, John Goerzen wrote:
> 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 might define just two IO functions:

parseConfig :: FilePath -> IO Config
modifyConfig :: FilePath -> (Config -> Config) -> IO Config

This way, you could do all the modification in pure functional code, which as
Alastair said, would create a "new" Config rather than modifying the
existing one.

Of course, you could also define a

writeConfig :: FilePath -> Config -> IO ()

but then a user of your class could accidentally overwrite a change, if you
had two parts of the code which read the same config, each made separate
changes, and then each wrote their separate changes.
-- 
David Roundy
http://www.abridgegame.org
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Rethinking OO idioms

2004-09-30 Thread Bayley, Alistair
There are three pieces to this story:
 - read a config file into some structure
 - query/modify elements of that structure
 - write structure out to a file

Create a data structure (analogous to a class with no methods) and functions
to query/manipulate that structure. Nested FiniteMaps might be a good,
simple, first attempt. Unlike the functions to read and write the file
(which must be in the IO monad), the functions to query and manipulate the
structure can (and probably should) be non-monadic.

Ben suggested using Parsec for reading the config file. Parsec is a fine
library, but there is a learning curve, and you might find it quicker to do
the parsing yourself, if it's very simple. Your call.

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

When you "modify" a structure, you return a new copy of it, where the bit
that you wanted to change is replaced by the new value. For example, this is
what happens when you call addToFM/delFromFM for FiniteMaps. This isn't
necessarily as expensive as it sounds, as there's a lot of data sharing
going on in Haskell programs, due to the fact that everything /is/
immutable.

If it does turn out to be too expensive, then you could look at using a
state monad. But assuming you need one immediately looks like premature
optimisation to me.

Alistair.

-
*
Confidentiality Note: The information contained in this 
message, and any attachments, may contain confidential 
and/or privileged material. It is intended solely for the 
person(s) or entity to which it is addressed. Any review, 
retransmission, dissemination, or taking of any action in 
reliance upon this information by persons or entities other 
than the intended recipient(s) is prohibited. If you received
this in error, please contact the sender and delete the 
material from any computer.
*

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rethinking OO idioms

2004-09-29 Thread Ben . Yu
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 

  <[EMAIL PROTECTED]To:   [EMAIL PROTECTED]
  
  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
[EMAIL PROTECTED]
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 [EMAIL PROTECTED]
immediately

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Rethinking OO idioms

2004-09-29 Thread John Goerzen
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
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe