The operation
(filter (`notElem` "'\"").[(1,'a','%',"yes"开发者_StackOverflow)])
gives an error. How can apply this filter on that list properly?
You've got a couple of serious problems. First, your syntax is wacky (.
definitely shouldn't be there). But the bigger problem is that what you're trying to filter is of the type [(Int,Char,Char,[Char])]
(that is, a list containing a 4-tuple).
And your list has only one element, which is (1,'a','%',"yes")
. So filtering that is useless anyway. When function you provide for filtering must be of type a -> Boolean
, where a
is the type of all the elements of the list.
Seems like you wanted some sort of wonky heterogenous list or something.
The .
operator in Haskell is function composition -- it composes two functions together.
So your code,
(`notElem` "'\"") . [(1,'a','%',"yes")]
looks like the composition of the notElem
function and some list. That's just wrong.
Remove the .
, and make sure to show
the list first:
> filter (`notElem` "'\"") (show [(1,'a','%',"yes")])
"[(1,a,%,yes)]"
精彩评论