Problem specifying fst in tuple from list in filter

I can generate a tuple of (index,character) like this: zip [0..] ['A'..'Z'] To filter on an element in the list I can do: filter (== (0,'A')) $ zip [0..] ['A'..'Z']
[(0,'A')]
But that is very basic, I really want to select on index value (ie first item in pair). How do I specify the first part of tuple: filter (fst == 0) $ zip [0..] ['A'..'Z'] this doesn't work. Couldn't match expected type `(a1, Char) -> Bool' with actual type `Bool' In the first argument of `filter', namely `(fst == 0)' In the expression: filter (fst == 0) In the expression: filter (fst == 0) $ zip [0 .. ] ['A' .. 'Z']

You can go:
filter ((==0) . fst)
which is equivalent to
filter (\x -> fst x == 0)
On Thu, Jan 2, 2014 at 10:52 AM, Angus Comber
I can generate a tuple of (index,character) like this: zip [0..] ['A'..'Z']
To filter on an element in the list I can do:
filter (== (0,'A')) $ zip [0..] ['A'..'Z']
[(0,'A')]
But that is very basic, I really want to select on index value (ie first item in pair). How do I specify the first part of tuple:
filter (fst == 0) $ zip [0..] ['A'..'Z']
this doesn't work.
Couldn't match expected type `(a1, Char) -> Bool' with actual type `Bool' In the first argument of `filter', namely `(fst == 0)' In the expression: filter (fst == 0) In the expression: filter (fst == 0) $ zip [0 .. ] ['A' .. 'Z']
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

You probably want something like the following:
filter (\(index, char) -> index == 0) $ zip [0..] ['A'..'Z']
Functions can be defined anonymously via a lambda abstraction (e.g.
\(index, char) -> index == 0).
Stavros Mekesis.
Quoting Angus Comber
I can generate a tuple of (index,character) like this: zip [0..] ['A'..'Z']
To filter on an element in the list I can do:
filter (== (0,'A')) $ zip [0..] ['A'..'Z']
[(0,'A')]
But that is very basic, I really want to select on index value (ie first item in pair). How do I specify the first part of tuple:
filter (fst == 0) $ zip [0..] ['A'..'Z']
this doesn't work.
Couldn't match expected type `(a1, Char) -> Bool' with actual type `Bool' In the first argument of `filter', namely `(fst == 0)' In the expression: filter (fst == 0) In the expression: filter (fst == 0) $ zip [0 .. ] ['A' .. 'Z']
participants (3)
-
Angus Comber
-
David McBride
-
smekesis@csd.auth.gr