[Haskell-beginners] find an element in a list

David McBride toad3k at gmail.com
Sat Dec 26 14:59:26 UTC 2015


It sounds like you want to include x only if it is not already at the head
of the list.  Try this:

extractIfBegins x (y:ys)
  | x == y = ys
  | otherwise = x:ys

On Sat, Dec 26, 2015 at 9:19 AM, Fabien R <theedge456 at free.fr> wrote:

> As a newbie, I'm studying the pdf 'the Haskell road to logic, math and
> programming' and I'm stuck with one exercise.
> I want to extract x if x is at the beginning of a list.
> I thought to use something like this:
> extractIfBegins x [xs] | [xs] == (x:ys) = [ys]                          |
> otherwise = [xs]
>
> But ghci complains that ys is not defined.
> Without giving the answer, can someone give a hint about the approach to
> follow ?
>
> --
> Fabien
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151226/33ec6a4d/attachment.html>


More information about the Beginners mailing list