dom and optional values

1 view
Skip to first unread message

Stepan Zastupov

unread,
Oct 5, 2009, 7:27:01 AM10/5/09
to ocamljs discuss
Hi all. The select class provides method add : option -> option ->
unit. As DOM specify null may be passed as second argument in order to
append an option at the end. Also with empty select there is no other
way to append the option without passing null. I think this kind of
methods should require optional type. So I have two questions:
1) How optional type (option) will be translated to javascript?
2) Optional type and dom option has same name, which one should be
renamed/aliased? :)

Stepan Zastupov

unread,
Oct 5, 2009, 7:34:59 AM10/5/09
to ocamljs discuss
Oh, I found I can use Ocamljs.null, but it looks a bit dirty and
unsafe :(

Jake Donham

unread,
Oct 5, 2009, 8:03:45 PM10/5/09
to ocamljs...@googlegroups.com
2009/10/5 Stepan Zastupov <redc...@gmail.com>:

>
> Oh, I found I can use Ocamljs.null, but it looks a bit dirty and
> unsafe :(

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

Stepan Zastupov

unread,
Oct 6, 2009, 4:46:31 AM10/6/09
to ocamljs discuss
Ok, at least it works, thanks. Also there is some missing dom methods,
I'm going to fill a bug report today.
By the way, ocamljs saves some time for me (javascript debugging is
hell), so thank you guys for your work.

On 6 окт, 04:03, Jake Donham <jake.don...@gmail.com> wrote:
> 2009/10/5 Stepan Zastupov <redch...@gmail.com>:

Jake Donham

unread,
Oct 19, 2009, 5:53:41 PM10/19/09
to ocamljs discuss
On Oct 6, 1:46 am, Stepan Zastupov <redch...@gmail.com> wrote:
> Ok, at least it works, thanks. Also there is some missing dom methods,
> I'm going to fill a bug report today.
> By the way, ocamljs saves some time for me (javascript debugging is
> hell), so thank you guys for your work.

Hi Stepan,

Thank you for your bug reports. My wife and I have a newborn baby (as
of three weeks ago) so I have not had time to address them, but I hope
to get to them soon. Thanks also for your blog post at

http://redchrom.blogspot.com/2009/10/ocamljs.html

although I had to run it through Google Translate to read it :). Best,

Jake
Reply all
Reply to author
Forward
0 new messages