﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3573	Better support for generic types	Per Östlund	Martin Sjölund	"We currently don't seem to have any good way of implementing generic types, such as dynamic arrays, hashtables, etc. It should be possible to use redeclare to do this, e.g.:
{{{#!mo
package SomeTypePackage
  replaceable type T = ?;
  
  uniontype SomeType
    // Or maybe define T here?
    record TYPE
      T data;
    end TYPE;

    function new
      input T inValue;
      output SomeType outType = TYPE(inValue);
    end new;

    function get
      input SomeType inType;
      output T outValue;
    algorithm
      TYPE(outValue) := inType;
    end get;
  end SomeType;
end SomeTypePackage;
}}}
Trying to use this doesn't quite work though:
{{{#!mo
// Doesn't work, MetaModelica package dependency stuff fails.
package MyTypePackage = SomeTypePackage(redeclare type T = Integer);

// Same name as the import => ok. But can only be used once in each package.
package SomeTypePackage = SomeTypePackage(redeclare Type T = Integer);
import MyType = SomeTypePackage.SomeType;

MyType t = MyType.new(17); // ok
Integer i = MyType.get(t); // Doesn't work, the compiler ignores the redeclared type and uses the declared type instead.
}}}
So trying to use redeclare almost works, but has too many issues currently. Also, the whole uniontype-in-package deal is perhaps not the best way of doing this. It would be nice to allow top-level uniontypes, or something equivalent, since packages are mostly just in the way for these kind of things (uniontypes are not strictly necessary either). Or we can just handle it in some different way, as long as it's possible to implement generic types in a convenient way.

"	enhancement	closed	high	1.9.4	MetaModelica		fixed		Adrian Pop
