我这样做:如何做操作符重载?
let (-) (m:float[]) (n:float[])= [| for i = 0 to Array.length m - 1 do yield m.[i]-n.[i] |]
但是,为什么这是错的?
let y=1.0-0.0
以前没事!
Error 1 This expression was expected to have type float [] but here has type float E:\MyDocuments\Visual Studio 2010\Projects\curve intersection\newton\Module1.fs 28 7 newton
Error 2 This expression was expected to have type float [] but here has type float E:\MyDocuments\Visual Studio 2010\Projects\curve intersection\newton\Module1.fs 28 11 newton
我认为(M:浮动[])(N:浮动[])被设定的参数的类型,为什么1.0-0.0,浮浮动,而不是去使用( - )浮动浮子>浮动???
谢谢,这是reasion。为什么F#不喜欢C#,按类型标识参数? – Begtostudy 2010-08-25 08:23:19
因为他们是不同的语言?这里有一些相互作用,我不能在评论中总结。简而言之,在F#中,let-bound标识符不能被特别重载。 – Brian 2010-08-25 08:26:22