September 2017
Beginner to intermediate
396 pages
9h 46m
English
The reverse function is implemented as follows:
reverse xs = reverse' xs []
Here, we used an internal reverse' function with an extra argument.
The internal function reverse' is a worker function that actually does the work. Its signature is as follows:
reverse' :: [a] -> [a] -> [a]
It takes two arguments--the first one is the list that needs to be reversed and the second argument is where we store the result, that is, the reversed list. The recursion is implemented for the worker function reverse'.
There are two base cases for the input list:
reverse' [] rs = rs
Read now
Unlock full access