Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/library/cache.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/library/cache.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download)

1 : monnier 411 (*
2 :     * This is a simple cache datatype.
3 :     *
4 :     * -- Allen
5 :     *)
6 :    
7 : monnier 245 signature CACHE_REF =
8 :     sig
9 :    
10 :     type 'a cache
11 :    
12 :     val cache : ('a -> 'b) -> 'a -> 'b cache
13 :     val flush : 'a cache -> unit
14 :     val !! : 'a cache -> 'a
15 :    
16 :     end
17 :    
18 :     structure CacheRef :> CACHE_REF =
19 :     struct
20 :    
21 :     type 'a cache = 'a option ref * (unit -> 'a)
22 :    
23 :     fun cache f x = (ref NONE, fn _ => f x)
24 :    
25 :     fun flush (x as ref(SOME _),_) = x := NONE
26 :     | flush (x,_) = ()
27 :    
28 :     fun !! (r as ref NONE,f) = let val x = f() in r := SOME x; x end
29 :     | !! (r as ref(SOME x),f) = x
30 :    
31 :     end
32 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0