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