home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 729 b | 18 lines | [TEXT/MPS ] |
- (* Operations on references *)
-
- type 'a ref = ref of mutable 'a;;
-
- value prefix ! : 'a ref -> 'a = 1 "field0"
- (* "!r" returns the current contents of reference r.
- Could be defined as function ref x -> x. *)
- and prefix := : 'a ref -> 'a -> 'a = 2 "setfield0"
- (* "r := a" stores the value of a in reference r.
- Could be defined as fun (ref x) a -> (x <- a). *)
- and incr : int ref -> int = 1 "incr"
- (* Increments the integer contained in the given reference.
- Could be defined as fun r -> r := succ !r. *)
- and decr : int ref -> int = 1 "decr"
- (* Decrements the integer contained in the given reference.
- Could be defined as fun r -> r := pred !r. *)
- ;;
-