It&#39;s more natural to consider the cross product of no sets to be [[]] so your crossr becomes:<br><br>crossr [] = [[]]<br>crossr (x:xs) = concat (map (\h -&gt;map (\t -&gt; h:t) (crossr tail)) hd)<br><br>which we can rewrite with list comprehensions for conciseness:<br>
<br>crossr [] = [[]]<br>crossr (x:xs) = [ a:as |&nbsp; a &lt;- x,&nbsp; as &lt;- crossr xs ]<br><br>then look at the definition of foldr:<br>foldr f z []&nbsp;&nbsp;&nbsp;&nbsp; = z<br>foldr f z (x:xs) = f x (foldr f z xs)<br><br>and, considering (foldr f z) == crossr, you should derive the definition of f and z.<br>
<br><div class="gmail_quote">On Mon, Nov 24, 2008 at 5:43 AM, Larry Evans <span dir="ltr">&lt;<a href="mailto:cppljevans@suddenlink.net">cppljevans@suddenlink.net</a>&gt;</span> wrote:<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="Ih2E3d">On 11/23/08 13:52, Luke Palmer wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2008/11/23 Larry Evans &lt;<a href="mailto:cppljevans@suddenlink.net" target="_blank">cppljevans@suddenlink.net</a>&gt;:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<a href="http://www.muitovar.com/monad/moncow.xhtml#list" target="_blank">http://www.muitovar.com/monad/moncow.xhtml#list</a><br>
<br>
contains a cross function which calculates the cross product<br>
of two lists. &nbsp;That attached does the same but then<br>
used cross on 3 lists. &nbsp;Naturally, I thought use of<br>
fold could generalize that to n lists; however,<br>
I&#39;m getting error:<br>
</blockquote>
<br>
You should try writing this yourself, it would be a good exercise. &nbsp;To<br>
begin with, you can mimic the structure of cross in that tutorial, but<br>
make it recursive. &nbsp;After you have a recursive version, you might try<br>
switching to fold or foldM.<br>
</blockquote>
<br></div>
Thanks. &nbsp;The recursive method worked with:<br>
-{--cross.hs--<br>
crossr::[[a]] -&gt; [[a]]<br>
<br>
crossr lls = case lls of<br>
 &nbsp;{ [] &nbsp; &nbsp; &nbsp;-&gt; []<br>
 &nbsp;; [hd] &nbsp; &nbsp;-&gt; map return hd<br>
 &nbsp;; hd:tail -&gt; concat (map (\h -&gt;map (\t -&gt; h:t) (crossr tail)) hd)<br>
 &nbsp;}<br>
-}--cross.hs--<br>
<br>
However, I&#39;m not sure fold will work because fold (or rather foldr1)<br>
from:<br>
 &nbsp; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#12" target="_blank">http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#12</a><br>
<br>
has signature:<br>
<br>
 &nbsp;(a-&gt;a-&gt;a)-&gt;[a]-&gt;a<br>
<br>
and in the cross product case, a is [a1]; so, the signature would be<br>
<br>
 &nbsp;([a1]-&gt;[a1]-&gt;[a1]-&gt;[[a1]]-&gt;[a1]<br>
<br>
but what&#39;s needed as the final result is [[a1]].<br>
<br>
Am I missing something?<br><font color="#888888">
<br>
-Larry</font><div><div></div><div class="Wj3C7c"><br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>