albrow / fo

An experimental language which adds functional programming features to Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Syntactic ambiguity in generic type declarations.

zenhack opened this issue · comments

This is another issue that was raised in the go 2 generics draft design, and was cited as the reason not to use square brackets for type parameters:

https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md#design-summary-discarded-ideas-why-not-use-1

To summarize: what is the meaning of type Foo [T] int? is it an a generic type which does not actually use its type parameter, or is it an array with size T (where T would have to be a constant)?

Right now fo seems to treat it as an array if T is in scope, or a type parameter otherwise -- which is confusing, and I really don't like that it needs a symbol table to disambiguate.

@alanfo proposed using this syntax instead: type Foo[type T] int

The original gist:

https://gist.github.com/alanfo/72f07362d687f625a958bde1808e0c87#the-syntax-for-declaring-type-parameters

@zenhack thank you for pointing this out. I'm well aware of the ambiguities introduced by the current syntax and I agree that it is not perfect. However, in practice it has not been a big issue so far and I will be focusing on other features/fixes in the near future.

Tackling #2 and improving interop with vanilla Go is my main focus for now.

By the way there has been some discussion about alternative syntax in #10. I would like to keep all syntax-related proposals/feedback there if possible to make it easier to get a wholistic view of the topic. I'm closing this issue, but feel free to continue the discussion in #10.

I agree this isn't top priority. Moving it to #10 makes sense.