How to define outer constructor based on array size?

Well in your case using Foo{3}(eye(3),ones(3)) would be the trick. More generally you could consider using https://github.com/JuliaArrays/StaticArrays.jl if it fits your purposes.

Other than that the type-inference “issue” may not be an issue at all depending on your use case.
In my personal experience type-stability turned out to either be a huge issue or absolutely none at all.
My advice: Ask yourself how often and where this code will be executed. If the answer is “a few times in the top level scope of my script” then chances are you won’t notice its influence. However, if this code is to be executed in some inner function that is called very often, then it is likely a problem that should be redesigned.

In other words: make sure that the functions that are doing the heavy computations are themself type-stable. If that is the case, the it may not matter so much that they are invoked using dynamic dispatch (which would be the consequence when calling a function with the result of Foo(eye(3),ones(3))) . The key is benchmarking your code before trying to optimize it.

2 Likes