为什么fail
值会抛出异常?fine
价值有效。如果我删除inline
或转换't
为float
然后它工作。
[<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
错误信息:
未处理的异常:System.TypeInitializationException:'AdditionDynamicImplTable
3' threw an exception. ---> System.NotSupportedExcep tion: Dynamic invocation of op_Addition involving coercions is not supported. at Microsoft.FSharp.Core.LanguagePrimitives.dyn@2445[a,b,c](Type aty, Type bt y, Unit unitVar0) at Microsoft.FSharp.Core.LanguagePrimitives.AdditionDynamicImplTable
3..cctor () 的类型初始化程序---内部异常堆栈跟踪结束---在 Microsoft.FSharp.Core.LanguagePrimitives.AdditionDynamic[T1,T2,TResult]( T1 x, T2 y) 在 C:\Users\olsv\Docume nts\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\Program 中的 .$Program.main@()。fs:line 14 按任意键继续。. .