My Complete Lack of a Solution to the Covariant Assignment Problem

December 3rd, 2008 by egottlie

So I eventually figured out that my problem from the last post reduced to assigning values to statically-allocated variables whose declared types were covariant to the type of the values in such a way that the subtype and supertype require different amounts of memory to store.  Most languages, at this point, just give up and make variables whose declared type is a class actually a reference to an instance of that class.

Well not me, nosiree!  Instead of completely destroying programmers’ ability to statically allocate lexical variables of object type (which includes closures, in theory, since in theory closures and objects are equivalent), I’m just going to make it illegal to perform covariant assignments or returns.  Deca will still allow assignment from an alias to a subclass to an alias to a superclass, however, and it will also maintain the ability to pass arguments to functions by reference.  Combined, these will allow programmers to create and allocate static lexical variables of object or closure type and pass them freely into any function that accepts the correct superclass or function type, while still requiring programmers to use dynamic allocation or aliases to global, anonymous variables to pass objects and closures of dynamic type up the call chain.

To rationalize this design decision, sometimes a systems-programming language should expose the ugly guts of variable storage, right?

Leave a Reply