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 (21:52)
From: William Lovas <wlovas@s...>
Subject: Re: [Caml-list] Memoizing (was: static variables...)
On Tue, Jun 18, 2002 at 11:16:13AM +0200, Jacek Chrzaszcz wrote:
> If you write it like this, it works:
> [memoize snipped]
> let recfib recfib = function
>   | 0 | 1 -> 1
>   | n -> recfib (n-1) + recfib (n-2);;                                      
> let fib = memoize recfib;;
> Now fib 30 is instantaneous! The clue is to contruct a new
> hash and a new recursive function once for each application of
> memoize.

Aha, cool.  Thanks!

Of course, the limitation here is that you have to change all the recursive
definitions to the "delayed binding" sort (aside: does this construct have
a name in the theory?), so it's still not completely general.  I don't
suppose there's much that can be done about that, is there?

> PS. In caml you can write anything ;)

Of course!  It's just a matter of what looks nice :)

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