Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Go 2: add alias for interface {} as any #33232

Open
Lexkane opened this issue Jul 22, 2019 · 53 comments
Open

proposal: Go 2: add alias for interface {} as any #33232

Lexkane opened this issue Jul 22, 2019 · 53 comments

Comments

@Lexkane
Copy link

@Lexkane Lexkane commented Jul 22, 2019

I would lilke to be able to declare any type with keyword any instead of empty interface, like rune means alias int32.
Such feature make language more readable , without polluting declarations with many empty interfaces. Imho any keyword is perfect for such alias.

@alanfo
Copy link

@alanfo alanfo commented Jul 22, 2019

I often use a type alias for this which isn't much extra work:

type any = interface{}
@ianlancetaylor ianlancetaylor changed the title Proposal Go2: Add alias for interface {} as any proposal: Go 2: add alias for interface {} as any Jul 22, 2019
@gopherbot gopherbot added this to the Proposal milestone Jul 22, 2019
@ccbrown
Copy link

@ccbrown ccbrown commented Jul 23, 2019

I agree with the sentiment that interface{} is terrible for readability, but I'm really hoping Go 2 has good enough generics to make nearly all uses of interface{} an avoidable anti-pattern. If that happens, an any type probably wouldn't be warranted at all. But if for some reason generics just completely fall through, sure, I'd support a builtin any alias. I do agree that it would increase readability.

@dotaheor
Copy link

@dotaheor dotaheor commented Jul 23, 2019

I support this proposal, though not strongly.

In the early days of using Go, I often encountered the map[string]interface{} type, which is really confusing for a new gopher. I used it for about a year without knowing what it exactly means.

@whoiswentz
Copy link

@whoiswentz whoiswentz commented Jul 23, 2019

I support this proposal too.

Its simple to implements and the readability becomes better

@Freeaqingme
Copy link

@Freeaqingme Freeaqingme commented Jul 24, 2019

I don't support this proposal. The power of Go is that for many things there's a single way of doing things. A language gets bloated easily once we start adding additional syntaxes only because some people prefer one over the other.

People new to the language may initially learn the 'any' keyword, but then read existing code, and still have to look up the interface{} keyword. Effectively, the burden of learning the language increases, rather than decreases.

@MaerF0x0
Copy link

@MaerF0x0 MaerF0x0 commented Jul 24, 2019

Yes and on w/ what @Freeaqingme has said, we also must take care when creating different ways of doing the same thing because:

  1. It makes tooling more difficult: now go tools have to support a new path to the same thing, and likely the users of said tools will expect output to match their chosen flavor of alias.

  2. It reduces the token space for future golang iterations. Consider alternate uses for the any token in future iterations of the language. We lose the option of clear expressiveness if we choose to alias any to something that is already provided. Some random ideas of how any could be something else: it could refer to any length of array ([any]string) , it could refer to non ZeroValue elements in a slice ( any mySlice) like lodash's compact function .

The examples are unimportant, but the point should be clear. If we choose to make this our any then we're stuck with it for quite some time, likely for good.

@dotaheor
Copy link

@dotaheor dotaheor commented Jul 24, 2019

Besides readability reason, less verbose and weird (esp. for new gophers) is another good point of this proposal.

@Freeaqingme
I began using Go by using Go templates to serve some web pages, I didn't need understand what interface{} is. I just needed to know I can assign any vale to it. any is far better for this purpose.

When a gopher later suddenly realizes that any is just interface{}, it is a viva moment, which in fact helps gophers understand Go better.

@MaerF0x0

It makes tooling more difficult:

any is just an alias of interface{}, there are many aliases in Go. If a tool can't handle such cases, it is a not qualified tool.

and likely the users of said tools will expect output to match their chosen flavor of alias.

This is not what a qualified tool should do.

It reduces the token space for future golang iterations.

Builtin identifiers are not keywords, users can shadow them as needed.

@Freeaqingme
Copy link

@Freeaqingme Freeaqingme commented Jul 25, 2019

@dotaheor

I just needed to know I can assign any vale to it. any is far better for this purpose.

If you really believe interface{} is so bad, I'd suggest you extend this proposal to deprecate interface{} and eventually remove it. I'm not a fan of that either, but my primary argument was against having two keywords for essentially the same thing. That argument would be moot if interface{} keyword is removed.

@MaerF0x0

We lose the option of clear expressiveness if we choose to alias any to something that is already provided.

We still have 'whatever' and 'anythingReally' as alternatives 😋

@changkun
Copy link
Contributor

@changkun changkun commented Jul 25, 2019

Is there anyone cloud explain the historical reason of why interface{} is designed as interface{} rather than anything else?

@dotaheor
Copy link

@dotaheor dotaheor commented Jul 25, 2019

@Freeaqingme
any will not be a keyword, it will be just a builtin identifier, just like, rune and byte, etc.

interface{} means an interface type specifying no methods, which happens to make it act as the any type. interface{} is not a bad thing generally, but using it as the any type is bad for new gophers. It confuses many new gophers.

@fzipp
Copy link
Contributor

@fzipp fzipp commented Jul 29, 2019

@Freeaqingme

If you really believe interface{} is so bad, I'd suggest you extend this proposal to deprecate interface{} and eventually remove it. I'm not a fan of that either, but my primary argument was against having two keywords for essentially the same thing. That argument would be moot if interface{} keyword is removed.

@changkun

Is there anyone cloud explain the historical reason of why interface{} is designed as interface{} rather than anything else?

It's not a special design, but a logical consequence of Go's type declaration syntax.

You can use anonymous interfaces with more than zero methods:

func f(a interface{Foo(); Bar()}) {
    a.Foo()
    a.Bar()
}

Analogous to how you can use anonymous structs anywhere a type is expected:

func f(a struct{Foo int; Bar string}) {
    fmt.Println(a.Foo)
    fmt.Println(a.Bar)
}

An empty interface just happens to match all types because all types have at least zero methods. Removing interface{} would mean removing all interface functionality from the language if you want to stay consistent / don't want to introduce a special case.

@Freeaqingme
Copy link

@Freeaqingme Freeaqingme commented Jul 29, 2019

@fzipp good point. I realized that after posting my earlier comment as well. Then it makes zero sense to remove that.

I'm sticking with my original reply; we can simply explain why interface{} is interface{} and how it works. There's then no need to add an additional keyword that basically is/does the same thing.

@sirkon
Copy link

@sirkon sirkon commented Jul 30, 2019

@Freeaqingme

If you really believe interface{} is so bad, I'd suggest you extend this proposal to deprecate interface{} and eventually remove it. I'm not a fan of that either, but my primary argument was against having two keywords for essentially the same thing. That argument would be moot if interface{} keyword is removed.

There was a built in type alias working like

type byte = uint8

in every Go package from the very early days.

It is not me being this proposal supporter or the other way, just a well known fact.

@y-usuzumi
Copy link

@y-usuzumi y-usuzumi commented Aug 1, 2019

In Haskell when we write guards:

abs n
  | n < 0     = -n
  | otherwise =  n

where

otherwise = True

Just imagine how much less readable it is if one uses True in place of otherwise.

It's only good if there's a single GOOD way of doing things.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 27, 2019

If we are able to add generics to the language, then I suspect there will be many fewer cases where people write interface{}, so the alias would have correspondingly less value. Putting on hold pending a decision on generics.

@conilas
Copy link

@conilas conilas commented Sep 13, 2019

The any value acts like the top type in a type system and it may be usefull sometimes even with generics.

Say we have a higher order function that composes just for logs. You do not need a contract of anything like that for that type if you want to log the argument and then perform the action. Something like (take it as a pseudocode):

func add(a interface{}, b interface{}, action fn_type<args>){
  return fn(a, b) -> {
    fmt.Printf("%v %v", a, b)
    action(a, b)    
  }
}

The top type would be good in this case instead of writing interface{} either way, so I think this proposal still have some value.

@beoran
Copy link

@beoran beoran commented Sep 4, 2020

In the latest generics design, we find the following:

However, it‘s tedious to have to write interface{} every time you write a generic function that doesn’t impose constraints on its type parameters. So in this design we suggest a type constraint any that is equivalent to interface{}. This will be a predeclared name, implicitly declared in the universe block. It will not be valid to use any as anything other than a type constraint.

(Note: clearly we could make any generally available as an alias for interface{}, or as a new defined type defined as interface{}. However, we don't want this design draft, which is about generics, to lead to a possibly significant change to non-generic code. Adding any as a general purpose name for interface{} can and should be discussed separately).

I think the "It will not be valid to use any as anything other than a type constraint." is a bad idea. It is far more simple and consistent to allow the use of the any alias type any = interface{} everywhere, in the hope that as generics are introduced, we'll see it getting use less and less in non-generic code.

@billinghamj
Copy link

@billinghamj billinghamj commented Sep 9, 2020

I feel very strongly that any should either be allowed in both type parameters and everywhere else, or allowed nowhere at all. And quite strongly that it should be allowed.

Having a confusing-to-beginners pattern of using interface{} is negative

Having any which means the same thing but is only sometimes allowed will add to this confusion and thus is significantly worse

The only thing we must not do is make it more confusing. Adding any would be a nice improvement, but not conditionally

@quenbyako
Copy link

@quenbyako quenbyako commented Sep 23, 2020

I disagree too. Maybe in Dart, Typescript, Rust, etc. it can be good improvement, otherwise in go, you can just put in package simple file like
extra.go

package something

type any = interface{}
type null = struct{} // for channels f.e.

// something that you want to syntax sugaring

could be amazing practice! I mean, any/null is good, it's more readable, than interface{}/struct{}, but it can be implemented just now, in specific cases that you want.

@fzipp
Copy link
Contributor

@fzipp fzipp commented Feb 9, 2021

@g13013 Yes, any is an identifier for interface{}, like fmt.Stringer is an identifier for interface{String() string}.

@g13013
Copy link

@g13013 g13013 commented Feb 9, 2021

any is just an alias to interface{} it might be called an identifier, still it's the same thing, the point is, having two things that mean the same thing should be avoided.

@fzipp
Copy link
Contributor

@fzipp fzipp commented Feb 9, 2021

@g13013
Why do you not complain about having two ways to write fmt.Stringer?
You can write func f(s fmt.Stringer) {} or you can write func f(s interface{String() string}) {}

Why do you not complain about having two ways to write io.Writer?
You can write func f(w io.Writer) {} or you can write func f(w interface{Write(p []byte) (n int, err error)}) {}

Why is it suddenly a problem with any and interface{}?

@quenbyako
Copy link

@quenbyako quenbyako commented Feb 10, 2021

@fzipp if so, how to use json.Unmarshal without interface{}/any?

any could be just alias) but i agree, that this problem could be solved without change language specification

@g13013
Copy link

@g13013 g13013 commented Feb 10, 2021

@fzipp I would complain about func f(s interface{String() string}) {} and func f(interface{Write(p []byte) (n int, err error)}, we would definitely ban them in my team as it makes the code unnecessarily unreadable.

interface{} is an another story, its the de facto standard in go to accept any type, I think you got me wrong, if the go team choses to introduce any for generics, than the deprecation should happen in the documentation and guides not in the language itself, if we are willing to keep interface{}, then I would definitely prefer to write generics with interface{} instead of any.

@ucirello
Copy link
Contributor

@ucirello ucirello commented Feb 10, 2021

re: #33232 (comment)

Now that the proposal is accepted (#33502 (comment)), what's next?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 10, 2021

I believe the proposal here is to add a new predeclared identifier any that is an alias for interface{}.

I'll take this proposal off hold.

@nadiasvertex
Copy link
Contributor

@nadiasvertex nadiasvertex commented Feb 11, 2021

I strongly support use of "any" as an alias for interface{}, and I also support deprecation of interface{}. I think there may be an argument for having "any" and "anyref". The argument could be that "any" in a generic context has a different meaning and performance consideration than "any" in a non-generic context.

For example:

func M[T any](p1 T, p2 any) {
  // ...
}

The "p1" parameter is fundamentally different than the "p2" parameter. I can imagine some user confusion here.

That being said, I would like to discourage adopting two separate type names. I strongly support using "any" as both the generic constraint, and the alias for reflection-based polymorphism. Semantically "any" in both places means the same thing: a type must satisfy the constraint to be legally passed. There are differences in how the type looks to the user at compile time, but they aren't significant enough to warrant bifurcation.

@gudvinr
Copy link

@gudvinr gudvinr commented Mar 11, 2021

I don't think this is a good idea.

Semantically speaking, interface{} means "interface that holds value, whose type guaranteed to have empty method set". Important thing there is that interface{} does not define type of value. It just wraps value of concrete type to use it in runtime.

I see that recent rise in discussion is probably because of approval of type parameters and its any type parameter. It is wrong to extend its usage to language, because in scope of type parameters any means concrete type rather than value wrapped into interface{}.

This change can be misleading since one may assume that any is concrete type while it is not.

@quenbyako
Copy link

@quenbyako quenbyako commented Mar 11, 2021

@gudvinr in terms of go generics: interface{} == any, but any != interface{}. you can't set any value as any type, but you can set, for example (interface{})(nil)

@gudvinr
Copy link

@gudvinr gudvinr commented Mar 11, 2021

in terms of go generics: interface{} == any, but any != interface{}. you can't set any value as any type, but you can set, for example (interface{})(nil)

It makes perfect sense because in terms of generics interface{} and any both aren't types but type constraints which later will be deducted into concrete type. In second statement interface{} is a valid type for value that holds another value.

@quenbyako
Copy link

@quenbyako quenbyako commented Mar 11, 2021

@gudvinr absolutely not. In the world of golang, the interface{} is a type, same as fmt.Stringer, or error or even http.Server. The interface{} type itself is a pointer to anything that corresponds to the specified interface (f.e. error allows to store pointer to literally any value, that has at least Error() string method, interface{} allows to store pointer to literally any value that has at least be correct for go runtime). any is not a type as you correctly said, but it's constraint for specific types.

@fzipp
Copy link
Contributor

@fzipp fzipp commented Mar 11, 2021

I don't understand where the confusion or the desire to distinguish comes from.

These are interfaces:

any				// identifier
interface{}			// no identifier

fmt.Stringer			// identifier
interface{String() string}	// no identifier

error				// identifier
interface{Error() string}	// no identifier

You can use them as types:

var x any
var x interface{}

var x fmt.Stringer
var x interface{String() string}

var x error
var x interface{Error() string}

You can use them as constraints:

[T any]
[T interface{}]

[T fmt.Stringer]
[T interface{String() string}]

[T error]
[T interface{Error() string}]

An interface is not intrinsically a type or a constraint, it's just a method set. Whether an interface acts as a type or as a constraint depends on its usage position, not on its identifier or lack of identifier.

@nadiasvertex
Copy link
Contributor

@nadiasvertex nadiasvertex commented Mar 13, 2021

@gudvinr
Copy link

@gudvinr gudvinr commented Mar 14, 2021

@nadiasvertex If you consider yourself "advanced user" you probably already know that usage of empty interfaces kinda discouraged.
In reality, most code written by inexperienced folks won't naturally contain interface{}. There are limited number of cases where you can't avoid them and it's basically either libraries for data serialization or some sort of containers and wrappers (like sync/atomic).

These kind of libraries usually require interface{} as input parameter(s). Even then it's being converted to reflect.Value right at the beginning most of the time.
In some cases type parameters reduce usage of interface{} even more.
And most importantly, this alias won't benefit existing libraries in any way because rewriting them using new alias is waste of time.

So why bother adding alias for sake of adding it? It has zero impact on existing code, it can't be widely used by "learners" and "advanced users" only use interface{} in write-once kind of libraries.
It isn't better in any meaningful way outside of discussions on how cool it would be.

@gudvinr
Copy link

@gudvinr gudvinr commented Mar 14, 2021

@fzipp You should try to expand your example outside of definitions since they constructed in a way that only benefits your point but doesn't show difference in semantics while focusing on specific difference between having identifier or not.

In your last example, you only define constraints as type parameters. Code inside functions that use those parameters won't use these constraints explicitly.

While if you have interfaces as types you will probably use them a little more often than that. In that case, assigning something to variable of type any seems very wrong in statically typed language.

An interface is not intrinsically a type or a constraint, it's just a method set.

Interfaces are types that specify method sets. Not in some ephemeral sense, it is a struct that holds pointer and RTTI header.
And when you have some value with interface{} type you explicitly state that "value of that type will be wrapped in a struct".
It is well-known behaviour for advanced users and explained basically in every tutorial and article.

Alias for interface{} hides that subtle yet important meaning since any can easily be misinterpreted as "any type" which is not true. That means you must always keep this in mind this additional information.
For example, C++ users might assume that it works like auto and does some deduction at compile time.
If you have some previous experience with dynamically typed languages you might also wrongly assume that any has some properties that it doesn't have. Interfaces allow you to have type information in runtime but Go still statically typed language.

Constraints, on the other hand, are meta-types. You do not use constraint as a type inside parameterized function. In that case any literally means "any type" and after applying [T any] constraint, var value T will have value of type T, not type any.

@nadiasvertex
Copy link
Contributor

@nadiasvertex nadiasvertex commented Mar 14, 2021

@nadiasvertex If you consider yourself "advanced user" you probably already know that usage of empty interfaces kinda discouraged.

It doesn't matter if they are discouraged or not. They are the only mechanism that exists for accomplishing certain tasks. If you look through the go standard library you will see them used over and over. Whether or not a new user needs to (or should) "write" an interface{} taking function is immaterial since they certainly will need to use one.

For example, what is more immediately clear to a new user reading the following (real) prototype from the library:

func SliceStable(x interface{}, less func(i, j int) bool)

or

func SliceStable(x any, less func(i, j int) bool)

@nadiasvertex
Copy link
Contributor

@nadiasvertex nadiasvertex commented Mar 14, 2021

And when you have some value with interface{} type you explicitly state that "value of that type will be wrapped in a struct".

That's not true. You can turn integers into receivers with no more ceremony than a "type" statement. All function calls in go are statically bound at compile time. There is no implicit automatic runtime dispatch. While type assertions do invoke the reflection machinery, the asserted value is statically bound which (among other reasons) is why you have to check to make sure it worked before using it.

@gudvinr
Copy link

@gudvinr gudvinr commented Mar 14, 2021

They are the only mechanism that exists for accomplishing certain tasks. If you look through the go standard library you will see them used over and over.

As you may notice, I said exact same thing after sentence you quoted. These usages limited by basically libraries for data serialization or some sort of containers and wrappers.

For example, what is more immediately clear to a new user reading the following (real) prototype from the library

Neither. You still need to explain what to pass in documentation. This case is also covered by "type parameters reduce usage of interface{}". So I don't get what's your point here.
And you still don't pass value of "any type", you pass wrapped value of concrete type so it's probably important to have this information right on hand.

@gudvinr
Copy link

@gudvinr gudvinr commented Mar 14, 2021

And when you have some value with interface{} type you explicitly state that "value of that type will be wrapped in a struct".

That's not true.

What do you mean? This is struct that describes interfaces in Go runtime:

type iface struct {
	tab  *itab
	data unsafe.Pointer
}

type statement uses information from tab (which contains both interface type information and dynamic type information of stored type) to extract value from data. It is neither implicit nor automatic.

@fzipp
Copy link
Contributor

@fzipp fzipp commented Mar 14, 2021

@fzipp You should try to expand your example outside of definitions since they constructed in a way that only benefits your point but doesn't show difference in semantics while focusing on specific difference between having identifier or not.

In your last example, you only define constraints as type parameters. Code inside functions that use those parameters won't use these constraints explicitly.

@gudvinr Ok, here's an example with implementation:

func Concat1(a []fmt.Stringer) string {
	r := ""
	for _, s := range a {
		r += s.String()
	}
	return r
}

func Concat2[T fmt.Stringer](a []T) string {
	r := ""
	for _, s := range a {
		r += s.String()
	}
	return r
}

fmt.Stringer is an interface. In Concat1 it acts as a type, in Concat2 it acts as a type constraint. The difference in semantics between these two functions does not come from a difference in names (it's fmt.Stringer in both cases) but from a difference in usage position. So why should interface{} / any be an exception. Why artificially limit the scope of any as an identifier for interface{} to type parameter lists when this limitation does not exist for all the other interfaces. Implementation details like boxed in one case and not boxed in the other case (depends on how type parameters will be implemented) can't be the criterion as the fmt.Stringer example shows.

@atdiar
Copy link

@atdiar atdiar commented Mar 14, 2021

I think that all the debate stems from the overloading of interface with type constraints which I don't like.

Any is a constraint.
interface{} is a type that the overarching proposal wants to be allowed as a use to denote the same constraint.

The issue is that an interface has in general adhoc constraints itself (adhoc because the constraints are different depending on the compiler implementation of interface types)

Using interfaces as types as well asconstraints can be confusing at best.
Better way would be to have a notation to explicitly derive a constraint object from a type.

In our present case,

const Any = type constraint{
    interface{} 
} 

And even that needs to be looked into because the equality of constraints is not assured if we want to implement a constraint checker at the compiler level and not only user code.
In that case, we would need some type of constraint deriving function that would massage the type's constraint sets a bit.

Anyway, semantically, any should be different from interface{}.
It's more obvious when we look at interfaces and constraints in general.
Using constraints should not be boxing since constraints should not be types.
Using interfaces is boxing.
Having double semantics for interfaces is a bit unfortunate for future-proofing potential language changes.

[edit]
Cf. semantic subtyping for the warnings (the type systems are similar to Go but with variance.. We do not even have vatiance in Go which is actually great for constraint checking)

Also cf. intensional semantics where meaning is representation which is not the case for interfaces as constraints.

Cf. 2D semantics.

@fzipp
Copy link
Contributor

@fzipp fzipp commented Mar 14, 2021

I think that all the debate stems from the overloading of interface with type constraints which I don't like.

The fact that interfaces can also act as constraints is the whole genius and beauty of the type parameters design.

@atdiar
Copy link

@atdiar atdiar commented Mar 14, 2021

Unfortunately, I don't think it's manageable after having thought hard about it. It's confusing and the literature seems to warn against it.
I initially also thought that interfaces would be sufficient but the problem is that they are types.

@fzipp
Copy link
Contributor

@fzipp fzipp commented Mar 14, 2021

Unfortunately, I don't think it's manageable after having thought hard about it. It's confusing and the literature seems to warn against it.
I initially also thought that interfaces would be sufficient but the problem is that they are types.

The Featherweight Go paper has shown that interfaces as constraints work out. I'd be interested in the literature that you're referring to. I'm more worried about type lists in interfaces if they make some interfaces unusable as types. But I hear that they are working on an update to the design that addresses this.

@atdiar
Copy link

@atdiar atdiar commented Mar 14, 2021

Semantic subtyping is a variant of structural subtyping that has been implemented in an O-Caml based language.
They use a set theoretic interpretation of types.

They use a SMT solver to type check one of their language C-Duce if I remember well.

It's basically constraint type checking which is similar to having types as sets of propositions.

They even have the luxury of having variance bolted in the type system and make it still decidable if I still do remember well. Although I do not know how slow the type checking is because of it.

The warning is about a seemingly unrelated issue but that will apply here.
Can be found in "A gentle introduction to semantic subtyping" page 200. (available via a websearch)
This is about breaking the circularity problem in presence of arrow types (functions basically).
This is actually a similar issue to what I am hinting at.
Namely, the constraints on types are different from the constraints of types.
In other terms, do we have constraint sets first then types, or type-derived constraint sets?

Especially for interfaces.
And when solving, it needs to be taken into account for soundness.

@nadiasvertex
Copy link
Contributor

@nadiasvertex nadiasvertex commented Mar 15, 2021

They are the only mechanism that exists for accomplishing certain tasks. If you look through the go standard library you will see them used over and over.

As you may notice, I said exact same thing after sentence you quoted. These usages limited by basically libraries for data serialization or some sort of containers and wrappers.

Which means that new users especially need to understand them. Your argument that their use is limited and therefore not worthy of simplification does not hold up.

For example, what is more immediately clear to a new user reading the following (real) prototype from the library

Neither. You still need to explain what to pass in documentation. This case is also covered by "type parameters reduce usage of interface{}". So I don't get what's your point here.
And you still don't pass value of "any type", you pass wrapped value of concrete type so it's probably important to have this information right on hand.

The point is that inteface{} is a needlessly esoteric spelling of any type. We should just say "any".

@nadiasvertex
Copy link
Contributor

@nadiasvertex nadiasvertex commented Mar 15, 2021

And when you have some value with interface{} type you explicitly state that "value of that type will be wrapped in a struct".

That's not true.

What do you mean? This is struct that describes interfaces in Go runtime:

type iface struct {
	tab  *itab
	data unsafe.Pointer
}

I think I have trouble understanding your English. Certainly if you pass a type into a function that takes a value interface what you say is true. My point is that just because something acts as a receiver doesn't mean that the value has to be wrapped up into yet another object. Also, what you point to is an implementation detail, not a semantic requirement of the language. The machinery of the implementation can be changed without necessarily affecting the semantics of the language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet