Haskell “No instance for” error

前端 未结 3 1541
粉色の甜心
粉色の甜心 2021-01-19 18:59

I am trying to write a function that checks if a number is prime. I wrote this :

primeCheck :: Int -> Int -> Bool
primeCheck n i 
    | n == 2 = True
         


        
3条回答
  •  滥情空心
    2021-01-19 19:18

    The problem is in converting from the Int for use in sqrt. Change the last line to

    isPrime n = primeCheck n (floor (sqrt (fromIntegral n)))
    

提交回复
热议问题