<div dir="ltr">I recommending first trying out the `last' function in ghci.<div><br></div><div><font face="monospace, monospace">    Prelude> last []</font></div><div><font face="monospace, monospace">    *** Exception: Prelude.last: empty list</font></div><div><font face="monospace, monospace">    Prelude> last [1,2]</font></div><div><font face="monospace, monospace">    2</font></div><div><br></div><div>Instead of using</div><div><br></div><div><font face="monospace, monospace">    last [] = []</font></div><div><font face="monospace, monospace"><br></font></div><div>You can use<br></div><div><br></div><div><font face="monospace, monospace">    last [] = error "Empty list"</font></div><div><br></div><div>Where error is defined in a way such that it can take on any type.</div><div>In ghci</div><div><br></div><div><font face="monospace, monospace">    Prelude> :type error</font></div><div><font face="monospace, monospace">    error :: [Char] -> a</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 12 May 2015 at 12:09, Mike Meyer <span dir="ltr"><<a href="mailto:mwm@mired.org" target="_blank">mwm@mired.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><p dir="ltr">On May 12, 2015 1:32 AM, "Roelof Wobben" <<a href="mailto:r.wobben@home.nl" target="_blank">r.wobben@home.nl</a>> wrote:<br>
><br>
> Hello, <br>
><br>
> To practice recursion I try to make some functions of Data list myself on the recursive way.<br>
><br>
> First I will try last.<br>
><br>
> So I did this : <br>
><br>
> -- | Main entry point to the application.<br>
> module Main where<br>
><br>
> -- | The main entry point.<br>
> last' :: [a] -> a <br>
> last' [] = [] <br>
> last' (x:xs) = last xs<br>
><br>
><br>
> but now I see this error message : <br>
><br>
> src/Main.hs@6:12-6:14<br>
> Couldn't match expected type<br>
> a<br>
> with actual type<br>
> [t0]<br>
> a<br>
> is a rigid type variable bound by the type signature for last' :: [a] -> a at /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:5:10 Relevant bindings include last' :: [a] -> a (bound at /home/app/isolation-runner-work/projects/112712/session.207/src/src/Main.hs:6:1) …<br>
><br>
> I my oponion I have said that the input is a array and the output a string, </p>
</span><p dir="ltr">Except for saying list instead of array, I'd agree with that. But when you write last' [] = [], the output is [], which does not have the expected type of strong. So the actual type is a list.</p>
<p dir="ltr">You need to return a string.</p>
<br>_______________________________________________<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" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>