1) I solved this with pencil and paper. If you are not so concerned with generality, a natural Haskell expression is

sum [n | n <- [1..999],

n `mod` 3 == 0 || n `mod` 5 == 0]

Your solution can also be improved by a list comprehension that allows dropping the second argument of “divisible”:

euler1 = sum [i | i [Int] -> Bool

divides n = any ((== 0) . (mod n))

2) Probably the best way to write 4 million in Haskell is just 4*10^6. The compiler will statically evaluate this, so there’s no interesting performance penalty.

Interesting post, thanks!

]]>sum [n | n <- [1..999],

n `mod` 3 == 0 || n `mod` 5 == 0]

Your solution can also be improved by a list comprehension that allows dropping the second argument of “divisible”:

euler1 = sum [i | i [Int] -> Bool

divides n = any ((== 0) . (mod n))

2) Probably the best way to write 4 million in Haskell is just 4*10^6. The compiler will statically evaluate this, so there’s no interesting performance penalty.

Interesting post, thanks!

]]>