<div dir="ltr"><div><div><div>It sounds like you want to include x only if it is not already at the head of the list. Try this:<br></div><div><br></div>extractIfBegins x (y:ys)<br></div> | x == y = ys<br></div> | otherwise = x:ys<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 26, 2015 at 9:19 AM, Fabien R <span dir="ltr"><<a href="mailto:theedge456@free.fr" target="_blank">theedge456@free.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As a newbie, I'm studying the pdf 'the Haskell road to logic, math and programming' and I'm stuck with one exercise.<br>
I want to extract x if x is at the beginning of a list.<br>
I thought to use something like this:<br>
extractIfBegins x [xs] | [xs] == (x:ys) = [ys] | otherwise = [xs]<br>
<br>
But ghci complains that ys is not defined.<br>
Without giving the answer, can someone give a hint about the approach to follow ?<br>
<br>
--<br>
Fabien<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">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-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>