我试图覆盖+符号,以学习如何定义自己的类型.我是Haskell的新手,我似乎无法克服这个错误.
这是我简单的新类型:
newtype Matrix x = Matrix x
(+):: (Num a, Num b, Num c) => Matrix [[a]] -> Matrix [[b]] -> Matrix [[c]]
x + y = Matrix zipWith (\ a b -> zipWith (+) a b) x y
Run Code Online (Sandbox Code Playgroud)
当我尝试将其加载到ghci时,我收到错误
linear_algebra.hs:9:42:
Ambiguous occurrence ‘+’
It could refer to either ‘Main.+’, defined at linear_algebra.hs:9:3
or ‘Prelude.+’,
imported from ‘Prelude’ at linear_algebra.hs:1:1
(and originally defined in ‘GHC.Num’)
Failed, modules loaded: none.
Run Code Online (Sandbox Code Playgroud)
用我的代码替换我的最后一行代码
x + y = Matrix zipWith (\ a b …Run Code Online (Sandbox Code Playgroud)