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.

[Caml-list] Lazy recomputing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-06-01 (15:27) From: Hans Ole Rafaelsen Subject: Re: [Caml-list] Lazy recomputing
```On Tuesday 01 June 2004 14:59, skaller wrote:
> On Tue, 2004-06-01 at 21:43, Thomas Fischbacher wrote:
> > > Is there some trick to get it recomputed, other that keep a list of all
> > > dependent values, and "refresh" the table whenever some value is
> > > updated?
> >
> > This is not what the general concept of laziness is about.
> >
> > You need something different.
>
> What he actually needs is a generalisation: a partial evaluator.

Thanks, that got me on the right track.  The values are stored as functions in
the table.  That way they are not evaluated during initialization, and can be
forced reevaluated when needed.  Have to make my own access functions.

let _ =
List.iter
(fun (k,v) -> Hashtbl.add tbl k v)
[
("a", fun () ->  1);
("c", fun () -> ((Hashtbl.find tbl "b") ()) + ((Hashtbl.find tbl "a")
()));
("b", fun () -> 4);
]
let find tbl k =
Hashtbl.find tbl k ()

let replace tbl k v =
Hashtbl.replace tbl k (fun () -> v)

# let _ = find tbl "c";;
- : int = 5
# let _ = replace tbl "a" 7;;
- : unit = ()
# let _ = find tbl "c";;
- : int = 11
#

--
Hans Ole

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

```