-1
我想寫操縱多項式一些F#代碼,這部分我想列表重複的元素結合到這裏一個單一的元素是相關代碼:F#tail.Head加上名單
type PolynomialElem(Coeff : double, Power : int) =
member x.Coeff = Coeff
member x.Power = Power
let rec removeDuplicates (inlist:list<PolynomialElem>) (outlist:list<PolynomialElem>) =
match inlist with
|head:: tail ->if head.Power = tail.Head.Power then
PolynomialElem(head.Coeff + tail.Head.Coeff) :: removeDuplicates tail.Tail
else
head :: (removeDuplicates(tail))
|[] -> []
這將產生兩套不同的錯誤:
The head.Coeff + tail.head.Coeff produces a type mismatch saying "type double * int doesn't match type double"
而且編譯器是不滿的方式串聯IM名單,他說:
This expression was expected to have type PolynomialElem list but here has type PolynomialElem list -> PolynomialElem list
有什麼幫助嗎?
謝謝,這工作 – 2009-10-22 07:31:16