I hope I’ll be able to explain clearly enough what I’m looking for – it’s a bit tricky without getting into a lot of details about the use case. It’s basically about dependency injection.
Say that I have a module and within it, I define a type, let’s call it
Foo is not defined in the source of the module, but rather the declaration is done using
eval (it’s basically done in a module configuration step, as the actual definition of
Foo depends on external factors). This
Foo is an alias of another type (one of many possible types which don’t share a common supertype) which is provided in the configuration step.
Now, let’s say that I have a function
foo() which returns an instance of Foo. If I declare it like:
function foo() Julia has no problem compiling the code – and assuming that I properly set up the type, everything works when I invoke the function.
However, if I declare
function foo()::Foo Julia gets upset because
Foo is not defined when the source file is parsed. This makes sense, obviously – but it’s not very valuable. I would like to still be able to use the type hint - both for better understanding the code later, and for counting on Julia’s checks at runtime.
One thing that worked was to define
Foo as a
Union of all the possible types. But that requires including and loading all the other libraries, even though I only need one of them (the one passed in the configuration step).
So can I tell Julia “let me annotate this function with the return
type ::Foo even if it doesn’t exist yet – by the time I’ll use the function,
::Foo will be set, trust me, I’m a human and I know what I’m doing”?