Beware the defaulting

It started innocently enough. I was comparing execution times (as I usually do) between different programming languages. This time was the turn of OCaml. I’ve implemented in it the usual Project Euler #5 problem, because It’s easy and computationally not too expensive. This is the OCaml implementation:

Uhm.. 3 times slower then the OCaml version, must be the overhead introduced by list lazyness, I thought, because I’m creating an infinite list and asking to it for the next value until I find one that respect my predicate. So I said “Let’s try removing the infinite list” and I produced this:

I’ve also added the signature to aid the compiler with type inference. This version is slightly faster:

232792560
./euler5 0,62s user 0,11s system 96% cpu 0,761 total

But still slower than OCaml’s version. I was beginning to struggle with bang pattern and seq wizardry when I notices a warning by ghc-mod:

Defaulting the following constraint(s) to type `Integer’

It was referring to the last list, the one in the main function. So I thought “Let’s restrict it’s type to Int. After all, the Integer type allows numbers to be very huge, and you pay for this feature. Furthermore, I’m sure that my solution will be in the Int type range”. This is the final version: