18.5 Grouping Instance Variables

 < Free Open Study > 



18.5 Grouping Instance Variables

So far, the states of our objects have consisted of just a single reference cell. Obviously, more interesting objects will often have several instance variables. In the sections that follow, it will be useful to be able to manipulate all of these instance variables as a single unit. To allow for this, let's change the internal representation of our counters to be a record of reference cells, and refer to instance variables in method bodies by projecting fields from this record.

   c = let r = {x=ref 1} in         {get = λ_:Unit. !(r.x),          inc = λ_:Unit. r.x:=succ(!(r.x))};  c : Counter 

The type of this record of instance variables is called the representation type of the object.

   CounterRep = {x: Ref Nat}; 



 < Free Open Study > 



Types and Programming Languages
Types and Programming Languages
ISBN: 0262162091
EAN: 2147483647
Year: 2002
Pages: 262

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net