Argentum got Generics

A project log for Argentum programming language

compiled, leak-free, no-GC, fast, small, modular, type-safe, memory-safe high-level simple programming language

Andrey KalmatskiyAndrey Kalmatskiy 05/26/2023 at 22:040 Comments

Argentum classes and interfaces can be parameterized:

class UnorderedMap(Key, Value) { ... }
interface InStream(T) { ... }

These parameters can be used in inheritance, field and method declarations as well as inside methods.

class Map(K, V) {
   +Array(Pair(K, V));            // Base class parameterized with our class parameters
   getAt(key K) ?V { ... }        // Class parameters affect types of method prototypes
   setAt(key K, newVal V) { ... }
   forEach(visitor (K, V)void) { ... } // visitor lambda is typed with class parameters.
class Pair(A, B) {
  a = ?A;  // field `a` of type `Optional(A)` initialized with `none`
  b = ?B;  // Field types also depend on class parameters.

Right now the internal implementation of generics is does not allow instantiation-of and casts-to the parameters, but I can easily add them to the language in the future.

So bottom line is:

These generics do not introduce additional code, do not consume memory and do not cost CPU time.