What is the meaning of the '#' in the following signature?
val insertBefore : #node Js.t -> #node Js.t -> #node Js.t Js.opt -> unit
See the #-types
section of the OCaml reference manual (http://caml.inria.fr/pub/docs/manual-ocaml/types.html).
A function type #node -> t
takes an object of class node
or its subclass and returns t
.
For example,
class c = object method x = 1 end
let g : #c -> int = fun o -> o#x
Function g
can take an object of class c
or its subclass. #c
is an abbreviation of < x : int; ..>
therefore,
let h = (g : < x : int; ..> -> int)
is type-checked.