Close

Argentum got Generics

A project log for Argentum programming language

It automatically prevents all memory leaks. It doesn't use GC, so no pauses. It's compiled to machine code. It's crazy safe and fast.

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.

Discussions