<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>Nested Lists</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Hi all,<BR>
<BR>
If I have a list, and I'd like to convert it to a list of lists,<BR>
each of length n, I can use a function like bunch:<BR>
<BR>
bunch _ [] = []<BR>
bunch n as = let (c,cs) = splitAt n as in c:bunch n cs<BR>
<BR>
&gt; bunch 8 [1..16]<BR>
[[1,2,3,4,5,6,7,8],[9,10,11,12,13,14,15,16]]<BR>
<BR>
If I now want to do the same for the nested lists, I can compose<BR>
an application involving both map and bunch:<BR>
<BR>
&gt; map (bunch 4) . bunch 8 $ [1..16]<BR>
[[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]]]<BR>
<BR>
and I can &quot;bunch&quot; the new length 4 lists again:<BR>
<BR>
&gt; map (map (bunch 2)) . map (bunch 4) . bunch 8 $ [1..16]<BR>
[[[[1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16]]]]<BR>
<BR>
Clearly there is a pattern here involving the bunch function and<BR>
latterly, three Int parameters; 2, 4 and 8. My question is, can I<BR>
create a function that will take such parameters as a list, and<BR>
give the same result, for example:<BR>
<BR>
&gt; f [2,4,8] [1..16]<BR>
[[[[1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16]]]]<BR>
<BR>
or perhaps:<BR>
<BR>
&gt; f [bunch 2, bunch 4, bunch 8] [1..16]<BR>
[[[[1,2],[3,4]],[[5,6],[7,8]]],[[[9,10],[11,12]],[[13,14],[15,16]]]]<BR>
<BR>
I think it may not be possible because the type signature of f would<BR>
depend on the length of its list parameter; but I'm not sure.<BR>
<BR>
-Paul</FONT>
</P>

</BODY>
</HTML>