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

Kim-Ee Yeoh ky3 at atamo.com
Wed Jun 17 19:48:10 UTC 2020

On Thu, Jun 11, 2020 at 1:42 AM 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]
>From a beginners perspective, the second function looks perfectly
cromulent. After all, how should one indicate a list if not by enclosing it
with square brackets like this, [x]?

An x might or might not be a list, but [x] surely has to be one, yes?

But consider all the things that could be a list. Specifically, look at the

1. An empty list—which haskell denotes using []—is a list
2. [1,2,3] is a list
3. [1,1,1,…] is a list

In each of the cases above, what is the value of x in [x]?

Recall that haskell is a value-oriented language. Every identifier at the
term-level evaluates to something that has a well-defined type.

> 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
-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200618/5449afed/attachment.html>

More information about the Beginners mailing list