On Monday, October 2, 2017 at 11:10:58 PM UTC-7, Christian Surlykke wrote:
>
> Den mandag den 2. oktober 2017 kl. 21.33.04 UTC+2 skrev Dave Cheney:
>>
>> Back before aliases defined types used to be called named types, which 
>> permitted the existence of unnamed types.
>>
>> map[string]string 
>>
>> is an unnamed type
>>
>> type Dictionary map[string]string
>>
>> is a named type, its name is Dictionary 
>>
>> And the rules of assignment permitted assignment from or to an unnamed 
>> type.
>>
>>
> Aha, I see. Thanks for clarifying. 
>
> br. Chr.
>  
>
>> On Tuesday, 3 October 2017 06:26:44 UTC+11, Christian Surlykke wrote:
>>>
>>> Forgive me if this has been asked before. I've not been able to find a 
>>> diskussion about it.
>>>
>>> A snippet like this
>>>
>>> type AppleCount uint32
>>>
>>> var i uint32 = 7
>>>
>>>
Isn't uint32 an unnamed type?
 

> var ac AppleCount = i
>>>
>>> why did this fail?
 

>
>>> will fail to compile with an error like:
>>>
>>> cannot use i (type uint32) as type AppleCount in assignment
>>>
>>>
>>> OTOH code like this:
>>>
>>> type Dictionary map[string]string
>>> var m map[string]string = make(map[string]string)
>>> var d Dictionary = m
>>>
>>>
>>> compiles just fine.
>>>
>>> There is this about type definitions in The Go Programming Language 
>>> Specification:
>>>
>>> *A type definition creates a new, distinct type with the same underlying 
>>> type and operations as the given type, and binds an identifier to it.*
>>>
>>> TypeDef = identifier Type .
>>>  
>>> *The new type is called a defined type. It is different from any other 
>>> type, including the type it is created from.*
>>>
>>>
>>> which I would take to mean that the second snippet should be invalid. 
>>>
>>> Is this a bug or 'working as intended'? If it's working as intended, can 
>>> anyone explain the reasoning behind this?
>>>
>>> br. Christian Surlykke
>>>
>>

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