我是Haskell的新手,所以我不太明白這裏發生了什麼,除了它是使用返回值或值的類型錯誤。有人能解釋我做錯了什麼嗎?謝謝。在Haskell中輸入關於Real類型的錯誤
type Point a = (a,a)
-- Determine the true distance between two points.
distance :: (Real a, Floating b) => Point a -> Point a -> b
distance (x1,y1) (x2,y2) = sqrt((x1 - x2)^2 + (y1 - y2)^2)
* Couldn't match expected type `b' with actual type `a'
`a' is a rigid type variable bound by
the type signature for:
distance :: forall a b.
(Real a, Floating b) =>
Point a -> Point a -> b
at mod11PA.hs:12:13
`b' is a rigid type variable bound by
the type signature for:
distance :: forall a b.
(Real a, Floating b) =>
Point a -> Point a -> b
at mod11PA.hs:12:13
* In the expression: sqrt ((x1 - x2)^2 + (y1 - y2)^2)
In an equation for `distance':
distance (x1, y1) (x2, y2) = sqrt ((x1 - x2)^2 + (y1 - y2)^2)
* Relevant bindings include
y2 :: a (bound at mod11PA.hs:13:22)
x2 :: a (bound at mod11PA.hs:13:19)
y1 :: a (bound at mod11PA.hs:13:14)
x1 :: a (bound at mod11PA.hs:13:11
感謝您的編輯。 –