<div dir="ltr">Hello,<div><br></div><div>I'm currently going through the exercises in chapter 3 of Real World Haskell. One of the exercises challenges me to create a function which takes a list and makes a palindrome of it.</div><div><br></div><div>I tried to solve it this way:</div><div><div>palindrome :: [t] -> [t]</div><div>palindrome xs = xs ++ (reverse xs)</div><div>  where</div><div>    reverse []     = []</div><div>    reverse (x:xs) = (reverse xs) ++ x</div></div><div><br></div><div>But when I try to compile this I get this error:</div><div><div>Kapitel3.hs:14:32-33: error: …</div><div>    • Couldn't match type ‘t’ with ‘[t]’</div><div>      ‘t’ is a rigid type variable bound by</div><div>        the type signature for:</div><div>          palindrome :: forall t. [t] -> [t]</div><div>        at /Users/jona/programmering/haskell/boken/Kapitel3.hs:13:15</div><div>      Expected type: [[t]]</div><div>        Actual type: [t]</div><div>    • In the first argument of ‘reverse’, namely ‘xs’</div><div>      In the second argument of ‘(++)’, namely ‘(reverse xs)’</div><div>      In the expression: xs ++ (reverse xs)</div><div>    • Relevant bindings include</div><div>        xs :: [t]</div><div>          (bound at /Users/jona/programmering/haskell/boken/Kapitel3.hs:14:12)</div><div>        palindrome :: [t] -> [t]</div><div>          (bound at /Users/jona/programmering/haskell/boken/Kapitel3.hs:14:1)</div><div>Compilation failed.</div></div><div><br></div><div>It looks like I have used a function that want a list of lists, but I don't understand where.</div><div>Also, is there some way to declare the type of my reverse-function in this case?</div><div><br></div><div>Kind regards,</div><div>Jona Ekenberg</div></div>