English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
Obj.magic and existential types.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-06-21 (18:08)
From: Jake Donham <jake@d...>
Subject: Re: [Caml-list] Re: Obj.magic and existential types.
On Sat, Jun 20, 2009 at 1:30 AM, Daniel
Bünzli<daniel.buenzli@erratique.ch> wrote:
> Theoretically React may also work in browsers via o'browsers
> (http://ocsigen.org/obrowser) but I never tried.

I have not tried either, but from a cursory glance at the code I have
the impression that React's space safety relies on support for weak
references, which standard Javascript does not have.

> Correct me if I'm wrong but from my perspective froc is different from react
> in that it leaks memory (see example below) and is less thread friendly
> (because it uses global datastructures).

Less thread-friendly, sure. Leaks memory, yes in your example, but in
a less contrived usage, where dead references are underneath a bind,
froc cleans up after itself. E.g.:

  open Froc_afp;;

  let n = return 1;;
  let i = return 0;;

  let _ = i >>= fun i ->
    let m = n >>= fun x -> return (x + 1) in
    print_int (read m);
    return ();;

  let () =
    let iref = ref 0 in
    while true do
      incr iref;
      write i !iref;
      propagate ();
      Gc.full_major ();

As before a new value of m is created each time around the loop, but
since it is under the bind of i, froc is able to clean it up when i's
dependencies are recomputed.

Without weak references I don't know how else to implement space
safety. But I am prepared to be enlightened :). Best regards,