lua-users home
lua-l archive

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


On Wed, Sep 10, 2008 at 12:38 PM, Greg Fitzgerald wrote:
> Have you given any thought to implementing the generalized list
> comprehensions proposed by SPJ and Wadler?
>
> http://research.microsoft.com/~simonpj/papers/list-comp/

That paper is really interesting.  I had thought of some basic
extensions along "list comprehensions <-> set builder <-> SQL <->
map/grep" analogies but wasn't certain what form they would take.
This provides some clear directions to take this to the next level,
and the related work in Microsoft LINQ[1] shows a practical
implementation along some of these lines.

Some code snippets have been added to the "Possible extensions"
section of that wiki page to show what the generated Lua function code
corresponding to the "zip" and "group by" extensions to list
comprehensions might look like.  These correspond to, using a
Haskell-like notation in the paper,

  [ (x,y,z,w) | (x <- xs | y <- ys), (z <- zs | w <- ws) ]

  [ the x.name, sum x.deposit | x <- transactions, group by x.name ] .

The implementations are a bit different from the "translations" in the
paper as they make efficient use of Lua for/if/while/tables constructs
rather than functional map/grep/zip.

I'll probably move on to other things, but I think there's a lot of
potential for work in this direction.

[1] http://en.wikipedia.org/wiki/Language_Integrated_Query