A diff implementation of flatten that doesn't use the list concat method.