Haskell は初めてで、インスタンスを持つクラスを作成しようとしていました。
私は次のコードを持っており、それを言おうとしています: 1) ブランチは最初の位置に任意の型を保持できます。2) 線形のものを取り、数値を返すクラス Linear を作成します。 Branch が最初に保持するのは、Num クラスの一部です。
data Branch a = Branch a Integer deriving (Show, Eq)
class Linear l where
length :: (Num a) => l -> a
instance (Num a) => Linear (Branch a) where
length (Branch len _) = len
次のエラーが表示されます: Could not deduce (a ~ a1) from the context (Num a) bound by the instance definition at.....
私が言おうとしていることを Haskell で表現する方法を知っている人はいますか?