On Tuesday, January 5, 2021 at 11:31:44 AM UTC-5 Brian Candler wrote:

> Are you trying to make user-defined generic maps look more like built-in 
> ones?
>
> map[T1]T2  is hard-coded syntax in go. But so is m[k] for accessing 
> elements - and you can't use that in user-defined types anyway.
>
> Therefore I don't think it helps much to be able to write mymap[T1]T2 
> instead of mymap[T1, T2], because you can't use the corresponding 
> accessors.  You would need something like:
>
> func (m *MyMap[KT, VT]) set(k KT, v VT) ...
> func (m *MyMap[KT, VT]) get(k KT) VT ...
>
> Also: to create one of these objects there is more built-in syntax you 
> can't use:
>     v := make(mymap[T1]T2)   // won't work
>
> so you need to use a factory function. With your proposed syntax it would 
> be:
>     v := makemymap[T1]T2()
>
> which IMO is worse than
>     v := makemymap[T1, T2]()
>
> Example code: https://go2goplay.golang.org/p/2i3dgP2cKyz
>

You mixed up the current draft custom generic function syntax with OP's 
generic type syntax here.
It is no doubtful the result will be ugly. What about if the custom generic 
function syntax is consistent with built ones?
For example:

    v := MakeMyMap(mymap[T1]T2) 
 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9a5805c7-3074-471f-8ef1-a95b68130026n%40googlegroups.com.

Reply via email to