Hacker News new | ask | show | jobs
by coder543 1599 days ago
I think I understand what they're asking for. Consider a function that takes in a struct as one of the arguments.[0]

Currently, you would have to invoke it like so:

    svc.GetObjectWithContext(ctx, &s3.GetObjectInput{Bucket: bucket, Key: key})
But... why do you have to type "s3.GetObjectInput"? The function is taking in a concrete type (not an interface) for that argument, and there is only one possible type that you can pass in... so I agree with the person above that it should be possible to elide the type like so:

    svc.GetObjectWithContext(ctx, &{Bucket: bucket, Key: key})
Go already supports type elision in some places, such as...

    []someStruct{{Field: value}, {Field: value}}
instead of having to type

    []someStruct{someStruct{Field: value}, someStruct{Field: value}}
which would be equally pointless repetition.

[0]: https://docs.aws.amazon.com/sdk-for-go/api/service/s3/#S3.Ge...

3 comments

Yep exactly this ^^ thank you for providing great context that I should've added to the comment in the first place!
I would also love this. The current rules for when you're allowed to elide are nonsensical.
Ah yes, that does make sense, I would agree. That Rust doesn't have that (in any context that I know of) is one of its annoyances,