-1

The operation

(filter (`notElem` "'\"").[(1,'a','%',"yes")])

gives an error. How can apply this filter on that list properly?

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
thetux4
  • 1,583
  • 10
  • 25
  • 38
  • 4
    You're having enough issues with beginner material in Haskell, that I'd suggest joining the #haskell irc channel for help, rather than asking lots of easy questions on SO. – Don Stewart Apr 15 '11 at 23:58
  • Note, for those answering, this is a follow-on from http://stackoverflow.com/questions/5683210/showing-a-haskell-list-of-tuples-with-custom-syntax – Don Stewart Apr 16 '11 at 00:00
  • 1
    Id rather read some list tutorials actually. – thetux4 Apr 16 '11 at 00:01
  • 2
    "Learn You a Haskell" is a good one: http://learnyouahaskell.com/ – Don Stewart Apr 16 '11 at 00:05
  • 2
    You might benefit from Real World Haskell as well. I did. http://book.realworldhaskell.org/read/getting-started.html – Tim Perry Apr 16 '11 at 01:08
  • See also http://stackoverflow.com/questions/3030675/haskell-function-composition-and-function-application-idioms-correct-use – Don Stewart Apr 16 '11 at 20:21

2 Answers2

2

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.

Jonathan Sterling
  • 18,320
  • 12
  • 67
  • 79
1

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)]"
Don Stewart
  • 137,316
  • 36
  • 365
  • 468