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:
- Now it become very easy to implement a rich container and standard algorithms library right in the Argentum language without using C/C++.
- Switching to generics allowed to remove all type-casts from all examples, tests and tutorials. It dramatically simplified source code.
These generics do not introduce additional code, do not consume memory and do not cost CPU time.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.