You are viewing a single comment's thread. Return to all comments →
rev l = last l : (rev $ init l)
It will cause an error when getting last [] or init [].
last []
init []
works !
Easy way
rev l = reverse l
Fwiw, also rev = reverse works, but this is just copying.
looks good to me (of course together with rev [] = []). Can anyone say something about compared efficiency with the foldl solutions?
foldl
Reverse a List
You are viewing a single comment's thread. Return to all comments →
It will cause an error when getting
last []
orinit []
.works !
Easy way
rev l = reverse l
Fwiw, also rev = reverse works, but this is just copying.
looks good to me (of course together with rev [] = []). Can anyone say something about compared efficiency with the
foldl
solutions?