






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







c = let x = ref 1 in { get = λ :Unit. !x, inc = λ :Unit. x := succ !x };
c : { get : Unit → Nat, inc : Unit → Unit }
c.inc unit;
unit : Unit
c.get unit;
2 : Nat
ResetCounter = {get:Unit→ Nat, inc:Unit→ Unit, reset:Unit→ Unit}
Counter = { get : Unit → Nat, inc : Unit → Unit }; inc3 = (λ c:Counter. c.inc unit; c.inc unit; c.inc unit);
newResetCounter = λinit:Unit. let x = ref init in { get = λ :Unit. !x, inc = λ :Unit. x := succ !x reset = λ :Unit. x := init };
rc = inc3 (newResetCounter unit);
rc : ResetCounter rc.get unit; 4 : Nat
newResetCounter = λini:Unit. let r = { x = ref ini, init = ini } in { get = λ :Unit. !r.x, inc = λ :Unit. r.x := succ !r.x reset = λ :Unit. r.x := r.init };
rc = newResetCounter 0;
rc : ResetCounter
ResetCounterRep = { x : Ref Nat, init : Nat}
resetCounterClass = λr:ResetCounterRep. let super = counterClass r in { get = super.get, inc = super.inc, reset = λ :Unit. r.x := r.init };
newResetCounter = λini:Nat. let r { x=ref ini, init = ini} in resetCounterClass r;
SetCounter = {get:Unit→ Nat, set:Nat→ Unit, inc:Unit→ Unit};
setCounterClass = λr:CounterRep. λself: Source SetCounter. { get = λ :Unit. !r.x, set = λi:Nat. r.x := i, inc = λ :Unit. (!self).set (succ (!r.x)) };
dummySetCounter = { get = λ :Unit. 0, set = λi:Nat. unit, inc = λ :Unit. unit };
newSetCounter = λ : Unit. let r = { x = ref 1 } in let cAux = ref dummySetCounter in (cAux := (setCounterClass r cAux); !cAux);
sc = newSetCounter unit; sc.inc unit; sc.get unit;
Counter = { get : Counter → Nat, inc : Counter → Unit };