sumOfSquare :: Int -> Int -> Int
sumOfSquare a b = a * a + b * b
hipotenuse :: Int -> Int -> Int
hipotenuse a b = truncate(sqrt(x))
where x = fromIntegral(sumOfSquare a b)
squareCheck :: Int -> Bool
squareCheck n = truncate(sqrt(x)) * truncate(sqrt(x)) == n
where x = fromIntegral n
isItSquare :: Int -> Int -> Bool
isItSquare a b = squareCheck (sumOfSquare a b)
calc :: (Integral a) => a -> [(a, a, a)]
calc a = [(x, y, (hipotenuse x y)) | x <- [1..a], y <-[1..a], (isItSquare x y)]
錯誤消息:而另一一種類型的錯誤
Prelude> :load "some.hs"
[1 of 1] Compiling Main (some.hs, interpreted)
some.hs:16:74:
Couldn't match expected type `Int' against inferred type `a'
`a' is a rigid type variable bound by
the type signature for `calc' at some.hs:15:18
In the first argument of `isItSquare', namely `x'
In the expression: (isItSquare x y)
In a stmt of a list comprehension: (isItSquare x y)
Failed, modules loaded: none.
據我所知的 'x' 和 'y' 的類型。這樣對嗎?它是否正方要求Int。但是什麼是'x'和'y'?我認爲他們是詮釋。
哪一行是第16行? – luqui 2010-12-02 10:46:05