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 775 - (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 : leunga 775 val ! : 'a cache -> 'a
15 :     val := : 'a cache * 'a -> unit
16 : monnier 245
17 :     end
18 :    
19 :     structure CacheRef :> CACHE_REF =
20 :     struct
21 :    
22 :     type 'a cache = 'a option ref * (unit -> 'a)
23 :    
24 :     fun cache f x = (ref NONE, fn _ => f x)
25 :    
26 : leunga 775 fun flush (x,_) = x := NONE
27 : monnier 245
28 : leunga 775 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 : monnier 245
31 : leunga 775 val op := = fn((r, _),x) => r := SOME x
32 :    
33 : monnier 245 end
34 :    

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