Function returning counter function

/// When called with a single argument, returns a function /// that counts the number of times it has been calledletcreateCounterinitial=letstate=refinitial
(fun () ->letcurrent=!statestate:=current+1current)
// Create a counter and call it a few timesletcounter=createCounter0letn0=counter ()
letn1=counter ()
letn2=counter ()

val createCounter : initial:int -> (unit -> int)

Full name: Script.createCounter

When called with a single argument, returns a function that counts the number of times it has been called