我有以下的代码:
如果我将
isInCircle::Double->Double->Bool
isInCircle p1 p2 = sqrt((p1*p1)+(p2*p2)) <= 1
当我进行以下类似的调用时:
isInCircle (random :: Double) (random :: Double)
我遇到了这个错误
* Couldn't match expected type `Double' with actual type `g0 -> (a0, g0)'
如果我将
isInCircle
函数的参数更改为IO Double
,那么在使用sqrt
和加法时会出现错误...
你能帮我吗?我的代码:
import System.Random
main :: IO ()
main = do
if isInCircle (random :: Double) (random :: Double)
then print "True"
else print "False"
isInCircle::Double->Double->Bool
isInCircle p1 p2 = sqrt((p1*p1)+(p2*p2)) <= 1
main :: IO () main = do if isInCircle (random :: Double) (random :: Double) then print "True" else print "False" isInCircle::Double->Double->Bool isInCircle p1 p2 = sqrt((p1*p1)+(p2*p2)) <= 1
- EvilGeniusIO Double
不是一个数字,而是生成一个数字的配方(或“操作”)的意思。 - melpomene