TODO: Improve the definition of length using foldR