我已经定义了以下类型(从代码中简化):
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:类型参数缺少约束'when(^ a或^?23604):( static> member(+):^ a*^?23604 - > ^?23605)'
在最后一行的"更长"一词.据我所知,它应该能够推断它总是添加'a'的两个成员.我怎么能摆脱这个?