| < Free Open Study > |
|
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 > |
|