Possibily, if you freeze the type of things that can be boxed by the interface. But what would it be useful for ?That would just mean that an interface is constant. Not even that the value it wraps can't be changed (because with the current implementation, the values an interface wraps need to be addressable).
Possibily, if you freeze the type of things that can be boxed by the interface. But what would it be useful for ?That would just mean that an interface is constant. Not even that the value it wraps can't be changed (because with the current implementation, the values an interface wraps need to be addressable).
It is not possible. Constants only exist at compile time.
Because an interface is a run time data structure, it cannot contain constants because they don't exist at run time.
No, I'm saying that the current implementation is two pointers.The value is addressed by the second pointer. So you cannot really put a const in an interface. (thought experiment)Of course, in the specific case of boxing a value type, that could work. If you accept that the *typ never changes throughout the program.
The question is, why a special case, what would you use it for? sync.Pools ?If it's just for error variables to be constants, maybe it is not worth it. What problem does it solve ?
Interfaces don't describe data, they describe behaviour. If you don't want the behaviour to be changeable, use a concrete type.
On Saturday, August 6, 2016 at 5:45:50 PM UTC+8, atd...@gmail.com wrote:No, I'm saying that the current implementation is two pointers.The value is addressed by the second pointer. So you cannot really put a const in an interface. (thought experiment)Of course, in the specific case of boxing a value type, that could work. If you accept that the *typ never changes throughout the program.
for constant intrfaces, the *typ property is not needed. Calling of their methods will confirmed at compile time.
The question is, why a special case, what would you use it for? sync.Pools ?If it's just for error variables to be constants, maybe it is not worth it. What problem does it solve ?
for safety.
On Saturday, August 6, 2016 at 11:53:42 AM UTC+2, T L wrote:
On Saturday, August 6, 2016 at 5:45:50 PM UTC+8, atd...@gmail.com wrote:No, I'm saying that the current implementation is two pointers.The value is addressed by the second pointer. So you cannot really put a const in an interface. (thought experiment)Of course, in the specific case of boxing a value type, that could work. If you accept that the *typ never changes throughout the program.
for constant intrfaces, the *typ property is not needed. Calling of their methods will confirmed at compile time.You need it, the interface cannot be of any type, it would need to be initialized with a value of a given type for method dispatch.The only thing is that the method dispatch would be fixed. (again a thought experiment :)
That's similar to sync.Value ( https://golang.org/pkg/sync/atomic/#Value)The question is, why a special case, what would you use it for? sync.Pools ?If it's just for error variables to be constants, maybe it is not worth it. What problem does it solve ?
for safety.What is trhe safety issue? Do you have an example at hand?