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 /MLRISC/releases/release-110.84/library/undoable-ref.sml
ViewVC logotype

Annotation of /MLRISC/releases/release-110.84/library/undoable-ref.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 411 - (view) (download)
Original Path: sml/branches/SMLNJ/src/MLRISC/library/undoable-ref.sml

1 : monnier 245 (*
2 :     * A reference that allows undo.
3 : monnier 411 *
4 :     * -- Allen
5 : monnier 245 *)
6 :    
7 :     signature UNDOABLE_REF =
8 :     sig
9 :     eqtype 'a uref
10 :     val uref : 'a -> 'a uref
11 :     val ! : 'a uref -> 'a
12 :     val := : 'a uref * 'a -> unit
13 :     end
14 :    
15 :     functor UndoableRefFn (Log : TRANSACTION_LOG) : UNDOABLE_REF =
16 :     struct
17 :    
18 :     type 'a uref = 'a ref * Log.version ref
19 :    
20 :     fun uref a = (ref a, ref(!Log.version))
21 :    
22 :     fun !! (r,_) = !r
23 :    
24 :     fun commit (x,v) = fn ver => v := ver
25 :    
26 :     fun rollback (x,v) =
27 :     let val x' = !x
28 :     in fn ver => (x := x'; v := ver)
29 :     end
30 :    
31 :     fun ::= (r as (x,v),y) =
32 :     let val ver = !Log.version
33 :     in if !v <> ver then (Log.add_object{rollback = rollback r,
34 :     commit = commit r
35 :     };
36 :     v := ver)
37 :     else ();
38 :     x := y
39 :     end
40 :    
41 :     val ! = !!
42 :     val op := = ::=
43 :     end
44 :    

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