[Haskell-beginners] List Comprehensions
Hamster
machamster at gmail.com
Wed May 11 13:36:30 CEST 2011
Hello,
I am trying to understand list comprehensions (I am very new to
Haskell) and there's one thing I simply don't understand.
If I have code that looks like:
combinations = [ (x,y) | x <-[1,2,3], y<-[1,2,3]]
Then it happily gives me all the possible combinations of x and y.
[(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)]
However...
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?
Thanks
H.
More information about the Beginners
mailing list