They explicitly decided agaisn’t type inference in the return type. I don’t remember the issue, but Andrew said it simplified the compiler and lead to more readable code.
Nothing in particular. When learning a new language I usually just try things out and see what works or does not, as I try to get a better understanding of how to use the language
You can write Type Functions to calculate return types, if there’s some kind of relation with the input type.
For example, in the parser combinator library mecha, there are two Type Functions ParserResult and ReturnType which calculate return types for some functions based on the type passed into a function through anytype.
ReturnType takes a type as a parameter, and depending on whether it’s a pointer to a function or a function itself, uses typeinfo to find the return type of the parse function.
Since all parsers wrap their results in a struct created through the Type Function Result, they store the type of the result value as a member of the struct, which ParserResult can directly access.
So when the exact relationship between the return type of a function and the input type is known, you can write a type level function to calculate the return type in place of actual return type deduction. It’s certainly not a replacement for complete return type deduction, but it can allow you to write functions you would otherwise have to rely on type erasure for (meaning returning *anyopaque then casting it back to its original type).