[Haskell-beginners] set multiplication

Christian Maeder Christian.Maeder at dfki.de
Tue Apr 8 07:06:29 UTC 2014


Some time ago I discovered that the monadic "sequence" function operates 
quite interestingly on lists. I don't know why you call it 
multiplication. I was looking for something like combinations:

Prelude> sequence [[1,2,3], [4,5], [6,7]]

HTH Christian

Am 08.04.2014 07:00, schrieb Nishant:
>
> 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
>



More information about the Beginners mailing list