lists strange behaviour

Hello, if I write down: [(x,y)|x<-[1..5],y<-[1..5]] I obtain as expected: [(1,1),(1,2),(1,3),(1,4),(1,5),(2,1),(2,2),(2,3),(2,4),(2,5),(3,1),(3,2),(3,3),(3,4),(3,5),(4,1),(4,2),(4,3),(4,4),(4,5),(5,1),(5,2),(5,3),(5,4),(5,5)] If I write down: [(x,y)|x<-[1..5],y<-[1..5],x==5] I obtain as expected: [(1,1),(1,2),(1,3),(1,4),(1,5)] but if I write: [(x,y)|x<-[1..5],y<-[1..5],x<-[1]] I obtain: [(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5)] Why????? Thank you in advance. Regards, Maurizio Connetti gratis il mondo con la nuova indoona: hai la chat, le chiamate, le video chiamate e persino le chiamate di gruppo. E chiami gratis anche i numeri fissi e mobili nel mondo! Scarica subito l’app Vai su https://www.indoona.com/

On Wed, Oct 28, 2015 at 5:52 PM,
but if I write: [(x,y)|x<-[1..5],y<-[1..5],x<-[1]] I obtain:
[(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5)]
Others will chime in with a full answer soon. Meanwhile, consider that [(x,y)|x<-[1..5],y<-[1..5],x<-[1]] (which is quite weird as a set-theoretic expression) is Haskell-equivalent to [(x,y)|_<-[1..5],y<-[1..5],x<-[1]] Now consider [(x,y)|y<-[1..5],x<-[1]] which is [(1,1),(1,2),(1,3),(1,4),(1,5)] as you expect. Separately, consider [ a | _ <- [1..5], f a ] where you can experiment with different values of f and a. Putting together the pieces will give you an answer to your query. -- Kim-Ee
participants (2)
-
galeonet@tiscali.it
-
Kim-Ee Yeoh