While working through Real World Haskell, I tried to perform a palindrome exercise using the following code solution:
palin :: [a] -> [a]
palin list = list ++ rev list
where rev list
| null list = []
| otherwise = rev (tail list) ++ (head list)
What caused "cannot build an error of infinite type. However, just replacing the parenthesis around the title with square brackets and it works correctly, as shown in the following example:
palin :: [a] -> [a]
palin list = list ++ rev list
where rev list
| null list = []
| otherwise = rev (tail list) ++ [head list]
I really do not understand why this matters, and I do not understand what it means "cannot build an infinite type a = [a]". Can someone explain this?
source
share