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@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@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners