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).



On Saturday, August 6, 2016 at 9:53:26 AM UTC+2, T L wrote:
>
> Is it possible to make an interface constant if its concrete value type is 
> bool/number/string?
>
> On Saturday, August 6, 2016 at 3:48:17 AM UTC+8, Ian Lance Taylor wrote:
>>
>> On Fri, Aug 5, 2016 at 11:21 AM, T L <tapi...@gmail.com> wrote: 
>> > 
>> > For an interface value, its internal values will never change. 
>> > Are there any problems if golang supports constant interface values? 
>>
>> Pedantically, in Go, constants are untyped by default.  It doesn't 
>> make sense to speak of an untyped interface value.  I would describe 
>> what you are asking for as an immutable variable.  I've often thought 
>> that immutable variables would be useful in Go, but since they have to 
>> be initialized it's not that simple.  For example, io.EOF is 
>> initialized using a function call.  That means that it can't actually 
>> be in read-only memory, and of course it's possible to take it's 
>> address.  How do we prevent it from being changed, without introducing 
>> an immutable qualifier into the type system?  It's a complex problem 
>> for which I have no solution.  And the benefits of an immutable 
>> variable aren't all that high. 
>>
>> 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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to