In order to improve the execution time checking whether a number is prime, I am trying to use a comprehension list up to the square root of n. When running the code, it's throwing errors related to not specifying a variable type (That I more less get but failed to fix). The initial advice I got was to have an Integer type as input and a Bool as output. However, I was trying to have a 'helper' function to get all the factors and then have the isPrime function to check whether n was prime.
This is the line of code:
isPrime n = [x | x <- [2..sqrt n], n `mod` x == 0]
This is the error after running the previous line
isPrime 100
<interactive>:12:1: error:
* Ambiguous type variable `a0' arising from a use of `print'
prevents the constraint `(Show a0)' from being solved.
Probable fix: use a type annotation to specify what `a0' should be.
These potential instances exist:
instance Show Ordering -- Defined in `GHC.Show'
instance Show Integer -- Defined in `GHC.Show'
instance Show a => Show (Maybe a) -- Defined in `GHC.Show'
...plus 22 others