Tại sao giá trị fail
ném một ngoại lệ? fine
giá trị hoạt động. Nếu tôi xóa inline
hoặc nếu tôi chuyển đổi 't
thành float
thì nó hoạt động. nhắnToán tử cộng tuyến trong cấu trúc ném ngoại lệ (F #)
[<Struct>]
type Test<'t> =
val x: 't
val y: 't
new (x,y) = { x = x; y = y }
static member inline (+) ((x,y), a: _ Test) = 0
static member inline (-) ((x,y), a: _ Test) = 0
let a = 1.,2.
let b = Test(1.,2.)
let fine = a - b
let fail = a + b
lỗi:
Unhandled Exception: System.TypeInitializationException: Loại initializer fo r 'AdditionDynamicImplTable
3' threw an exception. ---> System.NotSupportedExcep tion: Dynamic invocation of op_Addition involving coercions is not supported. at [email protected][a,b,c](Type aty, Type bt y, Unit unitVar0) at Microsoft.FSharp.Core.LanguagePrimitives.AdditionDynamicImplTable
3..cctor () --- End của nội ngoại lệ stack trace - - tại Microsoft.FSharp.Core.LanguagePrimitives.AdditionDynamic [T1, T2, TResult] (T1 x, T2 y) tại. $ Program.main @() trong C: \ Users \ olsv \ Docume nts \ Visual Studio 2012 \ Dự án \ Consol eApplication1 \ ConsoleApplication1 \ Program. fs: dòng 14 Nhấn phím bất kỳ để tiếp tục. . .