Skip to main content

Alias Semantics

In Morph, the default is assignment creates an alias — both names share the same underlying memory.


Default: Alias

x is 10;
y is x; // alias — y and x share memory
y is 20;
Print(x); // 20 (x changed too!)

The Four Memory Primitives

KeywordBehaviorC++ Equivalent
isAlias (shared memory)T& y = x;
anotherDeep copy (independent)T y = x;
moveOwnership transferT y = std::move(x);
address of / value ofPointer access&x / *p

Why Alias-by-Default?

  • No unnecessary copies → faster by default
  • Explicit another when you need a copy → clear intent
  • Matches the language philosophy of performance-first design

Next Steps