`Pair{A,B}` vs. `Tuple{A,B}`


So what’s the difference between Pair{A,B} and Tuple{A,B}? Why do we have both instead of one?

Map vs list comprehension

Types transport meaning. Same reason why we don’t always just use blobs of memory, even though everything boils down to that :wink:
E.g. you want to construct a pair with this syntax: a => b, but adding this constructor to Tuples won’t make much sense!


Tuples are much more low-level, being one of the few parts that are defined in non-Julia code in the src directory. They also have some slightly different behaviours than other types, such as allowing an arbitrary number of arguments, and being covariant,

julia> isa((1,3),Tuple{Real,Real})

julia> isa(1=>3,Pair{Real,Real})

Pairs on the other hand are just a regular immutable type.