It'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 ->map (\t -> 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 | a <- x, as <- crossr xs ]<br><br>then look at the definition of foldr:<br>foldr f z [] = 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"><<a href="mailto:cppljevans@suddenlink.net">cppljevans@suddenlink.net</a>></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 <<a href="mailto:cppljevans@suddenlink.net" target="_blank">cppljevans@suddenlink.net</a>>:<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. That attached does the same but then<br>
used cross on 3 lists. Naturally, I thought use of<br>
fold could generalize that to n lists; however,<br>
I'm getting error:<br>
</blockquote>
<br>
You should try writing this yourself, it would be a good exercise. To<br>
begin with, you can mimic the structure of cross in that tutorial, but<br>
make it recursive. After you have a recursive version, you might try<br>
switching to fold or foldM.<br>
</blockquote>
<br></div>
Thanks. The recursive method worked with:<br>
-{--cross.hs--<br>
crossr::[[a]] -> [[a]]<br>
<br>
crossr lls = case lls of<br>
{ [] -> []<br>
; [hd] -> map return hd<br>
; hd:tail -> concat (map (\h ->map (\t -> h:t) (crossr tail)) hd)<br>
}<br>
-}--cross.hs--<br>
<br>
However, I'm not sure fold will work because fold (or rather foldr1)<br>
from:<br>
<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>
(a->a->a)->[a]->a<br>
<br>
and in the cross product case, a is [a1]; so, the signature would be<br>
<br>
([a1]->[a1]->[a1]->[[a1]]->[a1]<br>
<br>
but what'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>