But using a function for this is wrong because macros allow you to load the vector at runtime w/o specifying types and without inner scope type-instability. So why insisting using a function instead of a macro? The only scenario I can think of is if the name of the file is only known at runtime and only inside some type-stable inner scope. But then some type-stable macro could help getting rid of the mess. I just don't see this mess happening in julia where you can use staged functions and macros; The solution would look much different than in C++. It could be coded as some DSL in a library which only exposes a nice API where you list the expected types and structure and that's it. Not a single 'if' would leak ;)
There are no free lunches of course, and yes, you could run into some mess but that seems would rarely happen. I would argue taht un that case no other language either can help you (they cant help to get this both fast clean) -- Julia, that's nothing to be ashemed of ;) Now if macros are somehow too constrained for such uses we could have a tag for functions as "type-unstable" in a form that prevents the type instability from leaking outside, but of course I'm looking for solutions within the current Julia state