I am learning Haskell and now i am resolving some exercises about declaring prelude functions without importing the prelude functions which i have to resolve.
I got stuck programming the reverse function because i noticed that i can't reverse the list without (++
) function. I tried using :
to concatenate the lists in a reverse way but it doesn't work. Can you explain me why only the first code works and the second not? Thanks.
Also I can't use pattern matching.
reverse1 :: [a] -> [a]
reverse1 = \list -> case list of {
[] -> [];
x:xs -> reverse1 xs ++ [x];
}
reverse1 :: [a] -> [a]
reverse1 = \list -> case list of {
[] -> [];
x:xs -> (reverse1 xs):(x);
}