On Fri, Jun 19, 2020 at 12:44 PM Brandon Bennett <[email protected]> wrote:
>
> I was playing around with a, probably not good, idea of what a rust-like 
> Return type would look like: https://go2goplay.golang.org/p/k0NKN9Q6Wc1
>
> It seems when we are returning a specific value like Result(int) from a 
> function as in
>
> func myFunc(input string) Result(int) {
>         return Err(int)(ErrBadValue)
> }
>
> That it would be nice if we didn't have to specify Err(int) and that it could 
> be inferred from the return type instead.

If I'm reading this right, you are suggesting that because the result
of Err is being assigned to a value of type Result(int) (via the
return statement) we should be able to use that fact to infer the type
argument of Err.  I think that would be possible for cases where we
are assigning to a variable of known type.  It's a little more
confusing when using := to assign to a variable whose type is not yet
known.  And it also seems unlikely to work when assigning to a
variable of interface type.

That is, I think we could make it work.  I would just want to be very
sure that it would never be confusing.  I think it's important that it
always be very very clear exactly what types got inferred, and how.

Thanks for the suggestion.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWKLjyQ8AsQ13%2Bwx%3DJeKR19Du0j0jfyqnKTTMUxjCitHQ%40mail.gmail.com.

Reply via email to