home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / cmlmcmpw.sit / Caml Light / Lib / ref.mli < prev    next >
Encoding:
Text File  |  1991-05-01  |  729 b   |  18 lines  |  [TEXT/MPS ]

  1. (* Operations on references *)
  2.  
  3. type 'a ref = ref of mutable 'a;;
  4.  
  5. value prefix ! : 'a ref -> 'a = 1 "field0"
  6.         (* "!r" returns the current contents of reference r.
  7.            Could be defined as function ref x -> x. *)
  8.   and prefix := : 'a ref -> 'a -> 'a = 2 "setfield0"
  9.         (* "r := a" stores the value of a in reference r.
  10.            Could be defined as fun (ref x) a -> (x <- a). *)
  11.   and incr : int ref -> int = 1 "incr"
  12.         (* Increments the integer contained in the given reference.
  13.            Could be defined as fun r -> r := succ !r. *)
  14.   and decr : int ref -> int = 1 "decr"
  15.         (* Decrements the integer contained in the given reference.
  16.            Could be defined as fun r -> r := pred !r. *)
  17. ;;
  18.