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

SCM Repository

[smlnj] View of /MLRISC/releases/release-110.60/library/undoable-ref.sml
ViewVC logotype

View of /MLRISC/releases/release-110.60/library/undoable-ref.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 245 - (download) (annotate)
Sat Apr 17 18:47:12 1999 UTC (20 years, 5 months ago) by monnier
Original Path: sml/branches/SMLNJ/src/MLRISC/library/undoable-ref.sml
File size: 763 byte(s)
version 110.16
(*
 *  A reference that allows undo.
 *)

signature UNDOABLE_REF =
sig
   eqtype 'a uref 
   val uref : 'a -> 'a uref
   val !   : 'a uref -> 'a
   val :=  : 'a uref * 'a -> unit
end

functor UndoableRefFn (Log : TRANSACTION_LOG) : UNDOABLE_REF =
struct

   type 'a uref = 'a ref * Log.version ref 

   fun uref a = (ref a, ref(!Log.version))

   fun !! (r,_) = !r

   fun commit (x,v) = fn ver => v := ver

   fun rollback (x,v) = 
   let val x' = !x
   in  fn ver => (x := x'; v := ver)
   end

   fun ::= (r as (x,v),y) = 
   let val ver = !Log.version
   in  if !v <> ver then (Log.add_object{rollback = rollback r,
					 commit   = commit r
					}; 
			  v := ver)
       else ();
       x := y
   end

   val !  = !!
   val op := = ::=
end

(*
 * $Log$
 *)

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