Write custom foldl' and foldr' methods

Additionally, use coercions to speed up folds.