Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Functional > Re: a question ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 18 Topic 2714 of 2972
Post > Topic >>

Re: a question about memoization

by Jon Harrop <usenet@[EMAIL PROTECTED] > Jan 5, 2008 at 09:26 AM

Stephen J. Bevan wrote:
> Jon Harrop <usenet@[EMAIL PROTECTED]
> writes:
>> In F#:
>>
>>   let memoize f =
>>     let m = Hashtbl.create 1
>>     fun x ->
>>       try m.[x] with Not_found ->
>>       let f_x = f x
>>       m.[x] <- f_x
>>       f_x
>>
>> The critical point is that the hash and equality functions are carried
in
>> the type automatically and do not need to be supplied separately by
hand.
>> This solution combined the correctness of SML with brevity of OCaml.
> 
> I'm quoting the above because it is the shortest, not because it is
> the only code with this issue: how do I flush the cache or is this an
> academic problem rather than a practical one?

The solution is still a practical one because there are many cases where
unbounded memoization is acceptable. For example, when loading glyphs.

Rather than providing an explicit "flush" function you would typically
replace the Hashtbl with something more appropriate, such as a weak hash
table that allows bindings to be garbage collected once it exceeds a
certain size, a round-robin scheme or a more sophisticated collection
strategy.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?u
 




 18 Posts in Topic:
a question about memoization
Michele Simionato <mic  2008-01-02 08:07:26 
Re: a question about memoization
Dr Jon D Harrop <jon@[  2008-01-02 08:52:39 
Re: a question about memoization
stephen@[EMAIL PROTECTED]  2008-01-05 06:03:47 
Re: a question about memoization
Jon Harrop <usenet@[EM  2008-01-05 09:26:13 
Re: a question about memoization
stephen@[EMAIL PROTECTED]  2008-01-05 17:36:40 
Re: a question about memoization
Jon Harrop <usenet@[EM  2008-01-05 19:39:46 
Re: a question about memoization
Vesa Karvonen <vesa.ka  2008-01-02 17:27:34 
Re: a question about memoization
Michele Simionato <mic  2008-01-02 23:53:04 
Re: a question about memoization
Vesa Karvonen <vesa.ka  2008-01-03 13:32:37 
Re: a question about memoization
Paul Rubin <http://phr  2008-01-03 05:37:47 
Re: a question about memoization
Michele Simionato <mic  2008-01-03 06:23:13 
Re: a question about memoization
Jon Harrop <usenet@[EM  2008-01-03 17:16:05 
Re: a question about memoization
Michele Simionato <mic  2008-01-03 09:40:41 
Re: a question about memoization
Jon Harrop <usenet@[EM  2008-01-04 07:26:32 
Re: a question about memoization
"David B. Benson&quo  2008-01-04 13:30:26 
Re: a question about memoization
Jon Harrop <usenet@[EM  2008-01-04 22:40:15 
Re: a question about memoization
"David B. Benson&quo  2008-01-04 15:38:03 
Re: a question about memoization
Jon Harrop <usenet@[EM  2008-01-04 23:45:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Aug 30 8:24:35 CDT 2008.