Similar to lists, tuples are a way to store multiple values into a single unit. However unlike a list, tuple elements can be of different types. So a tuple like `("dog", 23, 'l', 3.0)` is valid.

However tuple itself has a type:

``````λ: :t (1, 2, 3)
(1, 2, 3) :: (Num a, Num b, Num c) => (a, b, c)
λ: :t ("dog", 23, 'l', 3.0)
("dog", 23, 'l', 3.0)
:: (Fractional d, Num b) => ([Char], b, Char, d)
``````

You could create a list with elements: `[[1,2],[1,2,3],[2,3]]`, since each element is a list of numbers so are of same type. However you cannot create a list likeL `[(1,2), (1,2,3), (2,3)]` because `(2,3)` is a different type than `(1,2,3)`.

``````λ: :t [1, 2]
[1, 2] :: Num a => [a]
λ: :t [1, 2, 3]
[1, 2, 3] :: Num a => [a]
λ: :t (1, 2)
(1, 2) :: (Num a, Num b) => (a, b)
λ: :t (1, 2, 3)
(1, 2, 3) :: (Num a, Num b, Num c) => (a, b, c)
``````

Tuples are much more rigid because each different size of tuple is its own type, so you can’t write a general function like `sum`, `elem` for a tuple. You have to write functions for every type of tuple: 2-element, 3 element.

## Operations on Tuples

`fst` takes a pair and returns its first component.

``````fst ("cat", "dog")
``````
``````λ: fst ("cat", "dog")
"cat"
``````

`snd` takes a pair and returns its second component.

``````snd ("cat", "dog")
``````
``````λ: snd ("cat", "dog")
"dog"
``````

`zip` in haskell is similar to its counterpart in Python. If one list is longer than the other, the longer list elements are ignored. It’s lazy like everything else in Haskell and hence can be used to zip infinite lists with finite ones.

``````zip [1,3..10] [2,4..10]
``````
``````λ: zip [1,3..10] [2,4..10]
[(1,2),(3,4),(5,6),(7,8),(9,10)]
λ: zip [1,3..10] [100..]
[(1,100),(3,101),(5,102),(7,103),(9,104)]
``````

Get all right triangles which have lengths less than 10 and perimeter is 24.

``````λ: [(a, b, c) | c <- [1..10], b <- [1..9], a <- [1..b], a ^ 2 + b ^ 2 == c ^ 2, a + b + c == 24]
[(6,8,10)]
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.7775738,"math_prob":0.9986425,"size":1840,"snap":"2019-51-2020-05","text_gpt3_token_len":696,"char_repetition_ratio":0.10294118,"word_repetition_ratio":0.11204482,"special_character_ratio":0.45869565,"punctuation_ratio":0.29401088,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99677384,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-25T19:23:12Z\",\"WARC-Record-ID\":\"<urn:uuid:57728568-eba6-44f9-bb80-d4c9f563f23a>\",\"Content-Length\":\"10488\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:858daefe-55ec-4588-b9a0-442be5952311>\",\"WARC-Concurrent-To\":\"<urn:uuid:9c0cfdd0-7358-4231-80a6-1aa6ac428ca8>\",\"WARC-IP-Address\":\"104.24.98.184\",\"WARC-Target-URI\":\"https://www.fosspowered.com/programming/haskell/2018/08/15/tuples-in-haskell.html\",\"WARC-Payload-Digest\":\"sha1:MODYHG22TRSQVXSOGBYIOTGX6O3DAT5O\",\"WARC-Block-Digest\":\"sha1:IVESN44K76DO4LKGNUITAGQXWOLLUV5V\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579251681412.74_warc_CC-MAIN-20200125191854-20200125221854-00128.warc.gz\"}"}