menu
341 tokens

Extensions

Like impl in Rust but a little broader.

Extensions

  • Rust has impl blocks for as the sole mechanism for attaching members to nominal targets

  • TS++ has its as an additional mechanism

  • like impl in Rust but a little broader

  • inherent, anonymous, named extensions

  • E / T, T may be local or imported

  • extension of T

  • extension E of T

  • export extension of T

  • export extension E of T

  • an inhernt extension beside its target is visible wherever the target is visible

  • an anonymous extension on a foreign target is visible only in its declaring file

  • a named foreign extension must be imported explicitly

  • extension<T> of T: blanket extension

  • structural types, unions, and intersections cannot receive extensions

  • rustc coherence

  • overlapping implementations of one interface for one type, including blanket overlap, are errors

  • no orphan rule?

  • extension members are lexical, but implements contributes a program-wide relation whenever its module is in the program

  • global extensions considered for impls (not import order)

  • member overloading only within a single declaration block (extension or itme declaration)

  • also for @unsafe impls

src/extensions.ds.ds
1newtype UserId = string;2 3extension of UserId {4    value(this): string {5        string(this)6    }7}
  • extension members are lexical and import-scoped
  • interface implementations participate in the whole program (even if not imported/exported)