0
是否有可能將約束成員作爲第一類函數(給定對象)?如果是這樣,什麼是正確的語法使用?給定一個受成員約束限制的值,我可以作爲第一類函數訪問成員嗎?
// Example: property getter as a first-class function
type Test() =
member x.Value = "42"
let t = Test()
let getter = t.get_Value // works as expected
// now generically:
let inline getGetter< ^a when ^a : (member get_Value : unit -> string)> item =
// call getter
let value = (^a : (member get_Value : unit -> string) item)
// try to get getter as first-class function
let getter = item.get_Value // doesn't compile: "Lookup on object of indeterminate type..."
()
最有可能無關,但它是不一致的是'Test.Value'返回'int'而'getGetter'正在尋找'單元 - >字符串。 – ildjarn 2011-05-18 00:18:16
@ildjarn:謝謝。編輯。 (這在我的例子中只是一個錯誤,但不是真正的問題......) – wmeyer 2011-05-18 00:22:50