If I had a motorcade in Haskell:
x = (1, 2)
I could use fst x to get 1 and snd x to get 2
I was wondering if I had a triple:
y = (1, 2, 3)
Is there a similar function that I could use?
You need to write your own extractor functions:
extractFirst :: (a, b, c) -> a extractFirst (a,_,_) = a
Functions fstand are sndapplicable only for a set ie(a, b)
fst
snd
(a, b)
. , 1of2, 2of2, 1of4, 4of7. , , fst snd , :
1of2
2of2
1of4
4of7
4of7 (_, _, _, x, _, _, _) = x
lens, , .
lens
3of4 = view _3 4of4 = view _4 3of7 = view _3 ...
.
As already mentioned, the way to go is pattern matching. However, for completeness, I wanted to mention that you can just use the lambda function:
head $ map (\(a, b, c) -> a) (y : [])