Haskell错误 - "缺乏附带的绑定"

时间:2016-10-14 17:39:55

标签: haskell

我有以下haskell代码处理添加多项式:

module PolyLA2 where  -- defines the module name so you can import from another haskell file

type Coeff = Int
type Exp = Int
type Polynomial = [(Coeff, Exp)] -- a list of terms in a polynomial formula

addpoly::Polynomial -> Polynomial -> Polynomial
addPoly [] ys = ys -- Base case 
addPoly xs [] = xs -- Base case 
addPoly ((a,b):xs) ((c,d):ys)
     | a == c = ((a, b + d) : (addPoly xs ys))
     | a < c = ((a,b) : (addPoly xs ((c,d) : ys)))
     | a > c = ((c,d) : (addPoly ((a,b) : xs) ys)) 

我认为逻辑是正确的,但是当我尝试编译它时,我得到一个&#34;缺少伴随绑定错误&#34;我的问题是导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:5)

该行:

addpoly::Polynomial -> Polynomial -> Polynomial

应该是:

addPoly::Polynomial -> Polynomial -> Polynomial

注意字母P