How can I create a function type with custom Input and Output type

return_type is used internally by the compiler to infer types with the intent to generate good machine code within a “reasonable” compilation time budget. Pasting some stuff I said over on slack:

return_type approximates the return type of a function. The amount of approximation is tuneable and it can be helpful to return a more approximate (“wider”) type to reduce the amount of unproductive work type inference does. So this may be changed in the future.

If you use return_type in a way which can affect the meaning of your program, the program may break when the compiler team adjusts the inference heuristics.

Basically, the compiler team reserves the right to adjust return_type to balance the precision of type inference against the compilation cost. Less compilation cost means faster “time to first plot”, etc, which is great for the interactive user experience.

By the way, I can’t imagine @code_warntype going away, but if it did I’m sure the compiler team would be replacing it with some other mechanism to give you insight into compilation.

4 Likes