Fix foldLeft to be tail-recursive (foldRight, too)