我很难用jooc包装D3-力的一个子集。库不使用对象属性,而是实现融合的getter-setter函数。
simulation.force("x", d3.forceX()) // setter
simulation.force("x") // getter我想找到一种方法来模拟OCaml中的相同类型的多态性。这是我目前的情况
module Force = struct
class type force = object
(* not important *)
end
let x (): force Js.t = Js.Unsafe.meth_call __d3 "forceX" [||]
class type simulation = object
method force : string -> #force Js.t -> unit Js.meth
end
let simulation nodes: simulation Js.t =
Js.Unsafe.(meth_call __d3 "forceSimulation" [|inject nodes|])
end我想要的是
let s = Force.simulation nodes in begin
s##force "x" (Force.x ())
s##force "x" (* wishful thinking *)
end发布于 2016-07-30 11:47:16
class type simulation = object
method force_set : Js.js_string Js.t -> #force Js.t -> unit Js.meth
method force : Js.js_string Js.t -> #force Js.t Js.meth
endJs.js_string Js.t。force和force_set都将绑定到force。查看ocaml/2.8.1/手册/图书馆“方法名和下划线”https://stackoverflow.com/questions/38666861
复制相似问题