我想定义一个+-+
在此工作的运算符(称为它):
if a,b are Char => a +-+ b = [a][b]
if a,b are Integer => a +-+ b = a+b
我试过:
class Summable a where
(+-+) :: a -> a -> b
instance Summable Integer where
a +-+ b = a + b
instance Summable Char where
a +-+ b = [a] ++ [b]
但我得到了错误:
Couldn't match type `b' with `Integer'....
Couldn't match type `b' with `[Char]' ....
是否有可能做到这一点?如何?