Skip main navigation

Introducing Pairs in Haskell

Pairs are composite data structures in the Haskell programming language. In this video, Jeremy Singer explores how to build and access pairs.

Pairs, like lists, are a technique for building composite data out of individual values. A pair of Integers can be written as:

(1,2)

and a pair of Strings might be:

("apple", "banana")

Notice that pairs can also have elements with distinct types, for example:

(10, "green bottles")

A tuple is a generalization of a pair, since it has an arbitrary number of elements. In the comments below, please explore some differences between tuples and lists. Can you think of scenarios where one data structure would be more appropriate than the other?

This article is from the free online

Functional Programming in Haskell: Supercharge Your Coding

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now