18.3 Object Generators

 < Free Open Study > 



18.3 Object Generators

We have seen how to build individual counter objects, one at a time. It is equally easy to write a counter generatora 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 > 



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