General info about types

Type deduction for fields, lambda parameters, results, local variables and constants

Every value in Argentum has statically assigned type. For fields, constants, variables and lambda prototypes compiler deduces their types automatically by their initial values:

class MyClass {
   x = 2 + 3;     // int64 (inferred from int expression)
   s = "Hello";   // owning pointer to sys_String (inferred from string literal)
   z = true;      // bool
   v = Array;     // owning pointer to Array (inferred from the instance creation)
   w = &MyClass;  // weak pointer to MyClass (&ClassName expression creates unbound weaks)
fn myFunction() {
   a = MyClass;   // non-optional owning pointer to MyClass (points to a new instance)
   b = *a;        // shared-owning pointer to immutable MyClass
                  // (inferred from a freeze operator applied to MyClass instance)

Explicit type declarations:

Only function/method parameters/results need to be declared explicitly. Primarily because they may be defined in one module but used in another one. Thus their explicit types play documenting and enforcement roles.

Example of type declarations:

fn myFunction(
   i int,           // int64
   b bool,          // bool
   s String,        // temporary pointer to sys_String
   c &MyClass,      // non-owning weak pointer to MyClass
   a -Array(Point), // temporary pointer to an immutable Array of Point objects
   l (String, int) @Array(String)  // a lambda that takes a string and an integer
                                   // and returns a newly created array of strings
) @String {    // function returns an owning pointer to a newly created string

List of all Argentum types:

  • Primitive types: int, double, bool
  • Pointers to mutable objects: @Composition, &Association, Temp.
  • Shared pointers to immutable objects (aka const, frozen objects): *Aggregation, &*WeakConst and conform pointers to any objects (mutable or immutable): -Conform, &-WeakConform.
  • Callables:
    • Lambda (ParameterTypes)ResultType
    • Function fn(ParameterTypes)ResultType
    • Delegate &(ParameterTypes)ResultType
  • Optional type: ?BaseType

Leave a Reply

Your email address will not be published. Required fields are marked *