我对 Haskell 很陌生,在尝试编译Frag时遇到了这个错误。
src/AFRPVectorSpace.hs:51:25:
Could not deduce (Eq a) arising from a use of `/='
from the context (VectorSpace v a)
bound by the class declaration for `VectorSpace'
at src/AFRPVectorSpace.hs:(32,1)-(53,23)
Possible fix:
add (Eq a) to the context of
the class declaration for `VectorSpace'
In the expression: nv /= 0
In the expression:
if nv /= 0 then v ^/ nv else error "normalize: zero vector"
In an equation for `normalize':
normalize v
= if nv /= 0 then v ^/ nv else error "normalize: zero vector"
where
nv = norm v
相关代码:
class Floating a => VectorSpace v a | v -> a where
zeroVector :: v
(*^) :: a -> v -> v
(^/) :: v -> a -> v
negateVector :: v -> v
(^+^) :: v -> v -> v
(^-^) :: v -> v -> v
dot :: v -> v -> a
norm :: v -> a
normalize :: v -> v
v ^/ a = (1/a) *^ v
negateVector v = (-1) *^ v
v1 ^-^ _ = v1 ^+^ v1 -- (negateVector v2)
norm v = sqrt (v `dot` v)
normalize v = if nv /= 0 then v ^/ nv else error "normalize: zero vector"
where
nv = norm v
我的第一个猜测是我需要添加一个Deriving Eq
或类似的东西,但我不确定我到底需要做什么。