You're right, it is dirty and unsafe. But there isn't a good
alternative that I can think of (at least the way Ocamljs is designed
now).
Ocamljs translates the OCaml "lambda" intermediate language. In lambda
terms, an 'a option value in the heap is either a 0 for None or a
block with tag 0 and a pointer to the 'a value for Some. In Javascript
that becomes a 0 number or an array of length 1 containing the 'a
value.
A Javascript value that we get from the DOM might be null, which is
neither Some or None according to the heap representation. You can
write a function that tests whether it is null using Ocamljs.is_null
(or if you are passing one instead of receiving one, use Ocamljs.null)
in order to produce a safe interface.
However, when a DOM class is given an OCaml class type, there is no
place to put this safe translation function. It is just a type
description of the actual DOM class. If you want a safer interface on
top of the bare DOM class, you can add it of course.
Jake