| < Free Open Study > |
|
We have seen how to build individual counter objects, one at a time. It is equally easy to write a counter generator—a function that creates and returns a new counter every time it is called.
newCounter = λ_:Unit. let x = ref 1 in {get = λ_:Unit. !x, inc = λ_:Unit. x:=succ(!x)}; ▸ newCounter : Unit → Counter
| < Free Open Study > |
|