[Haskell-beginners] lists strange behaviour

Kim-Ee Yeoh ky3 at atamo.com
Wed Oct 28 11:01:18 UTC 2015

On Wed, Oct 28, 2015 at 5:52 PM, <galeonet at tiscali.it> wrote:

> 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


(which is quite weird as a set-theoretic expression)

is Haskell-equivalent to


Now consider


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151028/059f3c42/attachment.html>

More information about the Beginners mailing list