Thanks for the both quick answers.<br><br>This is what happens all the time, the thing I am trying to implement is already in the library!<br><br>Neil,<br>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.<br>
<br>Eugene, <br>I&#39;ll definitely have a look at the implementation of sequence.<br><br><br>Cheers!<br><br><br><div class="gmail_quote">2009/11/19 Neil Brown <span dir="ltr">&lt;<a href="mailto:nccb2@kent.ac.uk">nccb2@kent.ac.uk</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">Ozgur Akgun wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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.<br>

</blockquote>
<br></div>
Hi,<br>
<br>
The concise solution is the list monad, as already posted.  If that confuses you, here is a version using list comprehensions (well, mostly):<br>
<br>
allPossibilities :: [[a]] -&gt; [[a]]<br>
allPossibilities [] = [[]]<br>
allPossibilities (l:ls) = [ x : xs | x &lt;- l, xs &lt;- allPossibilities ls]<br>
<br>
The second line prefixes all possibilities from the later lists with every element from the the first list.  Note that the base-case is crucial; if it is the empty list [], that &quot;xs &lt;- allPossibilities ls&quot; will not find any elements, and thus the list comprehension becomes the empty list, and the whole thing falls apart.  Thus the base case must be the list containing the empty list, so that you have one possibility arising at the end upon which to prefix the items.  Hope that makes sense...<br>

<br>
Thanks,<br><font color="#888888">
<br>
Neil.<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Ozgur Akgun<br>