Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 :)

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