在类型上无法定义 (?) 操作符重载:
type Foo =
val s : string
new(s) = { s = s }
static member (?) (foo : Foo, name : string) = foo.s + name
let foo = Foo("hello, ")
let hw = foo? world
// error FS0043: The member or object constructor 'op_Dynamic'
// takes 2 argument(s) but is here given 1. The required signature
// is 'static member Foo.( ? ) : foo:Foo * name:string -> string'.
如果我使用独立的 let-binding 来定义操作符,则一切都正常:
let (?) (foo : Foo) (name : string) = foo.s + name
let hw = foo? world
但是我需要直接为类型Foo
指定op_Dynamic
运算符。第一段代码有什么问题吗?
使用F# 1.9.7.4
@Visual Studio 2010 Beta2