Trying to understand tuples and lists

Hi, I have a list of tuples ( characters and numbers ) . say, [('a', 1), ('b', 2)] I want to extract 'a' and 1 separately . (x,y) <- head [('a', 1), ('b', 2)] This doesnt work but my idea is to get x contain the value 'a' and y contain the value 1 as the first tuple in the list. Which is the right way of doing this. Thanks for your help. Cheers Karthik. __________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

I got get this working thanks to the fst and snd function.
Cheers
Karthik.
--- Karthik Kumar
Hi, I have a list of tuples ( characters and numbers ) .
say, [('a', 1), ('b', 2)] I want to extract 'a' and 1 separately .
(x,y) <- head [('a', 1), ('b', 2)]
This doesnt work but my idea is to get x contain the value 'a' and y contain the value 1 as the first tuple in the list. Which is the right way of doing this. Thanks for your help.
Cheers Karthik.
__________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
__________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree

Karthik Kumar
I got get this working thanks to the fst and snd function.
(x,y) <- head [('a', 1), ('b', 2)]
You could also (possibly easier to read) do it like the above, only use an '=' (x,y) = head [('a', 1), ('b', 2)] (The <- operator is used for monadic computations and list comprehensions: main = do x <- readFile ... or mapFst xs = [ x | (x,y) <- xs ] ) -kzm -- If I haven't seen further, it is by standing in the footprints of giants

Based on this and your previous post, I think you're not understanding what "<-"/"do" are for. I think you'll be better off forgetting them completely and using 'let/in' for now. let (x,y) = head [...] in ... is what you want. On Wed, 5 Nov 2003, Karthik Kumar wrote:
Hi, I have a list of tuples ( characters and numbers ) .
say, [('a', 1), ('b', 2)] I want to extract 'a' and 1 separately .
(x,y) <- head [('a', 1), ('b', 2)]
This doesnt work but my idea is to get x contain the value 'a' and y contain the value 1 as the first tuple in the list. Which is the right way of doing this. Thanks for your help.
Cheers Karthik.
__________________________________ Do you Yahoo!? Protect your identity with Yahoo! Mail AddressGuard http://antispam.yahoo.com/whatsnewfree _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Hal Daume III | hdaume@isi.edu "Arrest this man, he talks in maths." | www.isi.edu/~hdaume
participants (3)
-
Hal Daume III
-
Karthik Kumar
-
ketil+haskell@ii.uib.no