Coerce a 'a Js_of_ocaml.Js.t to a OCamlStruct.t

Context:

Let’s say we have

module A = struct
  type t = ...
end

Now, we want to use (iframe, webworker, messageport).postMessage on A.t

We need to do two things: 'a Js_of_ocaml.Js.t <-> A.t

How do we do that ?

Js.Unsafe.coerce seems to only get us 'a Js_of_ocaml.Js.t , not actual “ocaml types” i.e. I can’t remove the Js_of_ocaml.Js.t part.

Thanks!

That’s a use for the highly forbidden Obj.magic.

4 Likes