6
我已經定義了以下類型(從代碼簡化):類型推斷未能在泛型類型的靜態成員約束
type Polynomial<'a when 'a :(static member public Zero : 'a)
and 'a: (static member (+): 'a*'a -> 'a)
and 'a : (static member (*): 'a*'a -> 'a) > =
| Polynomial of 'a list
with
static member inline (+) (x: Polynomial<'a> , y : Polynomial<'a>) : Polynomial<'a>=
match x,y with
|Polynomial xlist, Polynomial ylist ->
let longer, shorter =
if xlist.Length> ylist.Length then xlist, ylist
else ylist, xlist
let shorterExtended = List.append shorter (List.init (longer.Length - shorter.Length) (fun _ -> LanguagePrimitives.GenericZero<'a>))
List.map2 (+) longer shorterExtended |> Polynomial
當我建我得到警告:
警告FS0193:一(^ a或^ 23604):(static> member(+):^ a *^23604 - >^23605)'
關於單詞「更長」在最後一行。據我所知,它應該能夠推斷出它總是添加兩個'a'成員。 我該如何擺脫這個?
不錯的解決方法。 – FZed