[Haskell-beginners] set multiplication

Mariano Pérez Rodríguez mariano.perez.rodriguez at gmail.com
Tue Apr 8 05:28:27 UTC 2014


It's been a while since I last wrote any Haskell code, but try:

setMulMany :: [[a]] -> [[a]]
setMulMany = foldr mulOne [[]]
    where
        mulOne :: [a] -> [[a]] -> [[a]]
        mulOne xs yss = [ x:ys | x <- xs, ys <- yss]

I'm writing this from my phone, so didn't have a chance to test it really...

Hope it helps!
On Apr 8, 2014 2:00 AM, "Nishant" <nishantgeek at gmail.com> wrote:

>
> hi,
>
> I am trying to implement a set multiplication program in haskell.
>
> Input : [1,2,3]   [4,5]  [6,7]
> Ouput : [ [1,4,6] , [1,4,7] , [1,5,6] , [1,5,7] ...]
>
>
> I implemented it for constant number of inputs like
>
> setMul xs ys zs =  [ [x] ++ [y] ++ [z] |  x <- xs , y<-ys ,z <- zs]
>
> I am not able to generalize this for any number of lists.
>
> type signature would be :
>
> setMulMany :: [[a]] -> [[a]]
>
> Example :
>
> Input : [ [1,2,3] , [4,5] , [6,7]]
> Ouput :  [ [1,4,6] , [1,4,7] , [1,5,6] , [1,5,7] ...]
>
>
>
> Regards.
> Nishant
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140408/8693b12a/attachment.html>


More information about the Beginners mailing list