Trying to understand tuples and lists
ketil+haskell at ii.uib.no
ketil+haskell at ii.uib.no
Wed Nov 5 13:47:55 EST 2003
Karthik Kumar <kaykaydreamz at yahoo.com> writes:
> 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
More information about the Haskell-Cafe
mailing list