added a simple version of the length function in terms of fold