[Haskell-cafe] (possibly) a list comprehensions question

2009-11-19 Thread Ozgur Akgun
Hi Cafe! I am struggling with an interesting problem while defining a function. It looks quite easy to me, but I couldn't manage to have a proper implementation yet. To illustrate what I'm trying to achive, I'll introduce special cases of the desired function, and hopefully build towards a solutio

Re: [Haskell-cafe] (possibly) a list comprehensions question

2009-11-19 Thread Eugene Kirpichov
You can easily use "sequence". The less easy part is understanding why it works. Are you familiar with monads? If you are not, try to take the source code of 'sequence', inline it and understand why *that* works. Prelude> map sum $ sequence [[1,2], [10,20], [100,200]] [111,211,121,221,112,212,122,

Re: [Haskell-cafe] (possibly) a list comprehensions question

2009-11-19 Thread Neil Brown
Ozgur Akgun wrote: Anyway, just forget the fact that these funstions do not do a check on the length of the input list for a moment. My question is, how can I generalize this function to accept a list of lists of arbitrary length, and produce the required result. Hi, The concise solution is

Re: [Haskell-cafe] (possibly) a list comprehensions question

2009-11-19 Thread Ozgur Akgun
Thanks for the both quick answers. This is what happens all the time, the thing I am trying to implement is already in the library! Neil, I clearly understood the way you implemented. Actually I had a similar implementation with some problems, one of which is the base-case you mentioned. Eugene,