[Haskell-beginners] Why do i need to take out the list for this to work

Bob Ippolito bob at redivi.com
Wed Jun 10 18:49:48 UTC 2020


Square brackets [] are pattern match syntax for lists. This will only work
for lists of length 1, anything else will be an error. Get rid of the
brackets on both sides of the equation and it will do what you expect.

Typically list variables are given plural names, such as xs instead of x.

On Wed, Jun 10, 2020 at 11:42 Alexander Chen <alexander at chenjia.nl> wrote:

> hi,
>
> assigment: make your own element function with the any function.
>
> --elem with any
> myElemAny :: Eq a => a -> [a] -> Bool
> myElemAny a = any (== a)
>
> --elem with any
> myElemAny' :: Eq a => a -> [a] -> Bool
> myElemAny' a [x]= any (== a) [x]
>
>
> myElemAny' compiles but throws an error because it has a non-exhaustive
> pattern. Could somebody tell me why the list gives the function grieveness?
>
> thanks,
>
> _______________________________________________
> 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/20200610/3b040bed/attachment-0001.html>


More information about the Beginners mailing list