[Haskell-beginners] List Comprehensions

Henk-Jan van Tuyl hjgtuyl at chello.nl
Wed May 11 13:46:34 CEST 2011


On Wed, 11 May 2011 13:36:30 +0200, Hamster <machamster at gmail.com> wrote:

> If I change the function to look like:
>
> combinations xs ys = [ (x,y) | x <-[xs], y<-[ys]]
>
> The output changes to:
> [([1,2,3],[1,2,3])]
>
> I don't understand what's going on there. Is there any way I can get
> it to produce all the combinations of a user supplied list?

Change the function to:
   combinations xs ys = [ (x,y) | x <- xs, y <- ys]

xs and ys are already lists; if you put square brackets around them, you  
get a list with another list as the only element.

Regards,
Henk-Jan van Tuyl


-- 
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--



More information about the Beginners mailing list