[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Local definitions inside list comprehensions



From: Kevin Hammond <kh@cs.glasgow.ac.uk>
Date: Thu, 24 Jan 91 17:56:35 GMT
To: Mark.Jones@prg.oxford.ac.uk, haskell@cs.glasgow.ac.uk
Subject: Re:  Local definitions inside list comprehensions
Sender: haskell-request@cs.glasgow.ac.uk

Just a brief reply since I'm living on borrowed time at the moment :-)

> I'd like to propose a small (but useful) extension to the syntax of
> Haskell list comprehensions.   [definitions in comprehensions]

See "Definitional List Comprehensions", K.Hammond, University of
Glasgow, January 1990 (distributed to the FP mailing list last year),
which proposes exactly this construct.  This has been implemented in
the Glasgow Haskell compiler as an experimental feature with an identical
syntax to that you propose.

There is an interesting relationship with Phil Wadler's monad comprehensions
(and an obvious application to monad comprehensions): definitions are
actually values in the identity monad.  This simplifies the definitions of
various monads which Phil uses in this paper.

There is also an open question over whether pattern-binding definitions in
this notation should be eliding (as are pattern-binding generators), or
should return errors (as with "where").  Again see the above paper for
details.

The syntax for null comprehensions which you suggest ([e|] = [e]) is actually
present in the Haskell report (by accident -- this may change for the next
release).  In his paper on monad comprehensions (LFP 90), Phil uses
this notation for the empty monad (actually [e|()]M, but this is equivalent).
For list comprehensions, the notation looks a bit clumsy in my opinion,
but your mileage may vary?

Glad to see other people find this notation appealing -- I think it 
significantly improves the expressiveness of an already powerful notation.

Kevin

PS	If people are interested, I can mail a PostScript version of my
	paper (but allow me some time to organise this!).