Version française
Home     About     Download     Resources     Contact us    
Browse thread
[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: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Lazy recomputing
On Wed, 2004-06-02 at 01:22, Hans Ole Rafaelsen wrote:
> 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);
>     ]

Of course, this will recompute the same result needlessly
to make sure it also computes the new result when needed.
Also the functions are bound to a particular hashtble,
which isn't so nice: might be nicer to write:

 fun tbl -> find tbl "b" + find tbl "a"

and 

let eval tbl key = find tbl key tbl;;
let tbl = create 97;;
let eval_tbl key = eval tbl key;;




-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
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