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


#1

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
#2

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!


#3

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})
true

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

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