Afaics, monomorphisation and trait objects could also be supported. I am thinking the polymorphic function (callee) can in some scenarios(1) be declared with trait bounds, but doesn't specify whether it expects a boxed trait object, a reference, a copy type, or a boxed hashtable lookup object. The caller will determine which version of the function is desired. The compiler can create the instance of the (callee) function required by the caller. Rust forces the decision at the function (for non-Copy
types) and the data type (for Copy
types) declarations, which seems at least in the former case to be premature optimization. I understand that by not declaring these invariants at the function declaration site, the caller is not forced to use a consistent option amongst the aforestated options, but isn't that desired?
Afaics, the immutability only applies when adding a data type to type parameter of a preexisting instance of a data type. All other operations can be mutable.
Afaics, the GC versus other mechanisms for managing the resource lifetimes is an orthogonal issue.
(1) Afaics, the supported scenario is where the callee doesn't apply other functions which make those aforementioned options polymorphic, or at least those functions invoked by the callee are not separately compiled. Note upthread where I employed the term 'module', I meant a separately compiled portion of code.