[MLton] List comprehensions?

Wesley W. Terpstra terpstra at dvs1.informatik.tu-darmstadt.de
Wed May 30 11:52:06 PDT 2007


On May 30, 2007, at 8:18 PM, Vesa Karvonen wrote:
> On 5/30/07, Wesley W. Terpstra <terpstra at dvs1.informatik.tu- 
> darmstadt.de> wrote:
>> I've been trying out haskell lately, and one thing I really like is:
>> list comprehensions!
>
> 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. What  
I find most useful is their recursive ability. 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.




More information about the MLton mailing list