私は次の型クラスインスタンスを持っています:
type Scalar = Double
data Vector = Vector [Double] deriving (Show, Eq)
instance Num Vector where
(+) (Vector xs) (Vector ys) = Vector (zipWith (+) xs ys)
(-) (Vector xs) (Vector ys) = Vector (zipWith (-) xs ys)
(*) (Vector xs) (Vector ys) = Vector (zipWith (*) xs ys)
instance Fractional Vector where
(/) (Vector xs) (Vector ys) = Vector (zipWith (/) xs ys)
dot :: Vector -> Vector -> Vector
dot (Vector v1) (Vector v2) = sum $ v1 + v2
しかし、ドット方式はタイプチェックを行いません。Vectorクラスにあるのに、+メソッドを使用できないと思います。
No instance for (Num [Double])
arising from a use of `+'
Possible fix: add an instance declaration for (Num [Double])
In the second argument of `($)', namely `v1 + v2'
In the expression: sum $ v1 + v2
In an equation for `dot':
dot (Vector v1) (Vector v2) = sum $ v1 + v2
編集:それは恥ずかしいことでした。