【发布时间】:2016-08-12 05:45:27
【问题描述】:
我正在尝试将 (PolyA a) 和 (PolyB a) 设置为多项式类的实例,我想在其中实现 coeffs、fromCoeffs、coeffsB、fromCoeffsB。我不太确定我做错了什么,因为我收到一条错误消息,指出我的函数对多项式类不可见。有什么帮助吗?
class Polynomial p where
--default implementations
data PolyA a = Coeffs [a]
deriving (Show)
data PolyB a = Const a | X (PolyB a) a
deriving (Show)
--instances
instance Polynomial (PolyA a) where
coeffs (Coeffs f)=f
fromCoeffs f= Coeffs f
instance Polynomial (PolyB a) where
coeffsB (Const f)= [f]
coeffsB (X f a)= coeffsB f ++ [a]
fromCoeffsB [] = error "Wrong Input!"
fromCoeffsB [f]= Const f
fromCoeffsB lis@(_:t)= X (fromCoeffsB (init lis)) (last lis)
【问题讨论】:
-
你没有在
class声明中定义任何函数。