<div dir="auto"><div>Thank you both for your answers, I somehow thought ++ acted as both append and concat, since I've mostly used it on strings where I haven't had to think about it.</div><div dir="auto"><br></div><div dir="auto">And thank you for the tips regarding adding explicit types and the reading material. So far I feel that I'm able to follow along quite well, but it's nice to have a second source!</div><div dir="auto"><br></div><div dir="auto">Grateful regards,</div><div dir="auto">Jona</div><div dir="auto"><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">Den 4 juli 2017 12:21 em skrev "Francesco Ariis" <<a href="mailto:fa-ml@ariis.it">fa-ml@ariis.it</a>>:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">On Tue, Jul 04, 2017 at 12:06:39PM +0200, Jona Ekenberg wrote:<br>
> Hello,<br>
><br>
> I'm currently going through the exercises in chapter 3 of Real World<br>
> Haskell. One of the exercises challenges me to create a function which<br>
> takes a list and makes a palindrome of it.<br>
><br>
> I tried to solve it this way:<br>
> palindrome :: [t] -> [t]<br>
> palindrome xs = xs ++ (reverse xs)<br>
>   where<br>
>     reverse []     = []<br>
>     reverse (x:xs) = (reverse xs) ++ x<br>
<br>
</div>Hello Jona,<br>
<br>
    let's analyse the error.<br>
It points to this bit:<br>
<div class="quoted-text"><br>
    palindrome xs = xs ++ (reverse xs)<br>
<br>
</div>And it says: I expected [[t]], but you gave me [t]. Whenever I encounter<br>
such an error I try to write explicit type signatures so to make diagnosing<br>
easier. In your example<br>
<div class="quoted-text"><br>
    palindrome :: [t] -> [t]<br>
    palindrome xs = xs ++ (reverse xs)<br>
      where<br>
</div>          reverse :: [t] -> [t] -- explicit type signature<br>
<div class="quoted-text">          reverse []     = []<br>
          reverse (x:xs) = (reverse xs) ++ x<br>
<br>
</div>If we :reload ghci complains again, the offending bit being<br>
<div class="quoted-text"><br>
    reverse (x:xs) = (reverse xs) ++ x<br>
</div>                                     ^<br>
Expected type is [t1] but we passed t. Not it is clear! The type of `++` is:<br>
<br>
    λ> :t (++)<br>
    (++) :: [a] -> [a] -> [a]<br>
<br>
and `x` is a single element. When we replace `x` with `[x]` everything works.<br>
<br>
Does that help?<br>
-F<br>
<br>
P.S.: Real World Haskell is an excellent book but sometimes can be a tad<br>
difficult to follow. If you want to integrate with another source, CIS194 [1]<br>
is an excellent choice: free, thorough, full of home-works and interactive.<br>
<br>
[1] <a href="http://www.cis.upenn.edu/~cis194/fall16/" rel="noreferrer" target="_blank">http://www.cis.upenn.edu/~<wbr>cis194/fall16/</a><br>
<div class="elided-text"><br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</div></blockquote></div><br></div></div></div>