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
[Caml-list] Memoizing (was: static variables...)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-06-18 (17:52)
From: Christopher Quinn <cq@h...>
Subject: Re: [Caml-list] Memoizing (was: static variables...)
Remi VANICAT wrote:
> no, an exception can be caused by the evaluation of the function to
> memoize. then the result of evaluating the function (which is the Exn)
> will be stored.

Yes, but assuming you do not intend for the function to be memoized 
itself to raise an exception, there is no opportunity in the code as 
given to create an initial Exn. So there is no chance of memoize raising 
an exception itself.

> this memoize function have several problem : 
> - it is not fully polymorphic (you have '_a type)
> - you cannot apply this function to two different function :
> the only way I see to resolve all those problem is to make:
> let new_memoize () =
>   let stow = Hashtbl.create 20
>   fun f x -> try
>      Hashtbl.find stow x
>   with Not_found ->
>      let v = f x in
>      Hashtbl.add stow x v;
>      v
> each call to new_memoize () will make a new memoize function that
> could be apply to one function.

I was, rather, interested in the purpose of Val|Exn in the original. But 
thanks for this improvement!

- chris

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