A quick change in your code that will โshortenโ the grade and rely on Haskell's laziness:
isPrime k = if k > 1 then null [ x | x <- [2..k - 1], k 'mod' x == 0] else False
The very first k divider will cause the list to be non-empty, and the null implementation on Haskell will only consider the first element of the list.
You only need to check before sqrt(k) however:
isPrime k = if k > 1 then null [ x | x <- [2..isqrt k], k 'mod' x == 0] else False
Of course, if you want to conduct high-performance simplicity testing, it is preferable to use a library.
tildedave
source share