I wonder why this performs really badly, though (I would expect it to be the same as s2): s3 :: Int -> Int s3 n = sum [gcd x y | x <- [ 0 .. n-1 ], y <- [ 0 .. n-1 ]]