[MLton] List comprehensions?

Vesa Karvonen vesa.a.j.k at gmail.com
Wed May 30 12:11:08 PDT 2007


On 5/30/07, Wesley W. Terpstra <terpstra at dvs1.informatik.tu-darmstadt.de> wrote:
> On May 30, 2007, at 8:18 PM, Vesa Karvonen wrote:
[...]
> > I have a recollection that Geoffrey Washburn has done something
> > related.  Aha, here it is:
> > http://osdir.com/ml/lang.sml.smlnj/2006-12/msg00010.html .
>
> Hmm. I don't think this really does list comprehensions, though.

Monad comprehensions are a generalization of list comprehensions.
Here is an article on the subject:
http://citeseer.ist.psu.edu/wadler92comprehending.html .

> What I find most useful is their recursive ability.

That feature is mainly due to the laziness of Haskell. :-)

> For an array comprehension, I want something like this:
>
> sizeSum :: Int -> Int -> Array Int Int
> sizeSum n s = a
>    where a = array (0,n) ([(0,0)] ++ [(i, f i) | i <- [1..n]])
>          f i = i + sum (map ((a!).(`div`s).((i-2)+)) [1..s])
>
> ... this is an actual function I needed to plot, but my point is that
> I could index the array while creating it.

I recall a discussion on a related topic on the MLton list:
http://mlton.org/pipermail/mlton/2006-March/028522.html .

-Vesa Karvonen



More information about the MLton mailing list