16 Aliasing

Now that we have references, we can have aliasing. This is when two refs point to the same location in memory

Here we have two distinct locations in memory, x and y.

Now, because z is equal to x, it points to the same location in memory.

Now updating x also updates z. Note that y hasn't changed:

Equaality in refs is weird. Let's say we have two refs:

The double equals sign (==) and the exclamation equals sign (!=) check physical equality. That is, they check to see if the two items point to the same location in memory.

The single equals sign (=) and the double angle brace (<>) is structural equality. They check to see if they contents of the location are the same.

You usually want to use single equals. Only use double equals if you want to check if two refs are aliases of each other.