/// Sets a dependency property
let inline setDP (prop: DependencyProperty) (v: obj) (target: ^a when ^a: (member SetValue: DependencyProperty * obj -> unit)) =
( ^a : (member SetValue: DependencyProperty * obj -> unit) (prop,v))
target
除了最简单的类型之外,我无法弄清楚如何为任何东西做鸭子打字。我收到错误Expected 3 expressions, got 2
。我不知道这意味着什么。
答案 0 :(得分:0)
像这样:
/// Sets a dependency property
let inline setDP (prop: DependencyProperty) (v: obj) (target: ^a when ^a: (member SetValue: DependencyProperty * obj -> unit)) =
( ^a : (member SetValue: DependencyProperty * obj -> unit) (target,prop,v))
target
我惊讶于它的语法有多么质朴。这个和struct语法肯定是F#中的两个弱点。