Make scanl use a reference instead of a variable.