2026-08-20
MyReverse.hs
myReverse :: [a] -> [a]
myReverse = undefined -- write this
Implement myReverse without using the built-in reverse.
Reference
myReverse :: [a] -> [a]
myReverse = foldl (flip (:)) []
Fold left over the list, consing each element onto the front of the accumulator as you go — by the time you reach the end, the accumulator is the list in reverse.