Function returning counter function

A simple function that creates a counter function (with localized mutable state).