[Python-Dev] Re: Python / Haskell (fwd)

gvwilson@nevex.com gvwilson@nevex.com
Tue, 29 Feb 2000 11:38:41 -0500 (EST)


[Forwarded to this list with Phil Wadler's permission.]

> Greg Wilson wrote:
> Hi, Phil.  I was talking to a couple of colleagues over the weekend,
> one of whom learned Miranda as his second language and never really
> recovered :-).  I was wondering: if you could add one or two features
> of Haskell to Python, what would you choose?  And why?

Philip Wadler <wadler@research.bell-labs.com> wrote:

Well, what I most want is typing.  But you already know that.

Next after typing?  Full lexical scoping for closures.  I want to write:

	fun x: fun y: x+y

Not:

	fun x: fun y, x=x: x+y

Lexically scoped closures would be a big help for the embedding technique
I described [GVW: in a posting to the Software Carpentry discussion list,
archived at

  http://software-carpentry.codesourcery.com/lists/sc-discuss/msg00068.html

which discussed how to build a flexible 'make' alternative in Python].

Next after closures?  Disjoint sums.  E.g.,

	fun area(shape) :
	  switch shape:
	    case Circle(r):
	      return pi*r*r
            case Rectangle(h,w):
	      return h*w

(I'm making up a Python-like syntax.)  This is an alternative to the OO
approach.  With the OO approach, it is hard to add area, unless you modify
the Circle and Rectangle class definitions.  On the other hand, with
disjoint sums it is hard to add a new shape, unless you modify all the
existing switch statements for shapes.  This is a well-known tradeoff, see
e.g., the discussion in my paper with Odersky on Pizza, or the ECOOP 98
paper by Felleisen and Krishnamurthi.

[GVW: the Pizza paper is available from:

  http://cm.bell-labs.com/cm/cs/who/wadler/topics/gj.html

The Felleisen and Krishnamurthi paper is at:

  http://www.cs.rice.edu/CS/PLT/Publications/#tr98-299

]