-
Notifications
You must be signed in to change notification settings - Fork 35
Alternative generic syntax discussion #10
Comments
To extend this, it would also make it easier to differentiate between slices and the generics. |
I first started out by trying to use angled brackets since that is the syntax I was familiar with from other languages. I quickly found that it made the parser too difficult. Consider the following pathological example: Square brackets still lead to ambiguity in the parser, but it is much easier to deal with. The expression Other languages such as Scala and Nim also use square brackets for generics. All that being said, I don't want to say that the syntax will never change. Feel free to propose alternatives here but try to keep in mind the trade-offs and why I chose square brackets. I'll also mention that I'm probably not going to change the syntax anytime soon. Since this syntax works for now, I'd rather focus on fixing bugs and adding new features. There are also some relevant comments on Reddit about this issue. |
@ohir proposed using special unicode characters. I'm not in favor of this proposal because they are hard to type and can look too similar to other characters. |
That’s a really exhaustive (and understandable) answer, thanks for taking the time! |
Lets start with shortened examples (see #12 for more) func (b Box∘T∘) Map∘U∘ (f func(T) U) Box∘U∘ {}
func (b Box∫T∫) Map∫U∫ (f func(T) U) Box∫U∫ {}
func (b Box⟅T⟆) Map⟅U⟆ (f func(T) U) Box⟅U⟆ {}
func (b Box⟨T⟩) Map⟨U⟩ (f func(T) U) Box⟨U⟩ {} @NullVoxPopuli (of #12) yes, math angle brackets glyphs are, esp for an old eye and in some fonts, are similar in shape to the parenthesis. That's why I'd shown more possibilities. @albrow
and voilá - you have all four On other platforms are either vimmers who will use maps coming from @albrow P.S. For persistent map you may put
into your |
I’m happy with the answer given, will close this for now. If the time and effort needed to use < and > is available some day I’m all for it! Feel free to reopen if you want. 😊 |
@maxekman I'm actually going to re-open this so that it is more obvious for anyone who wants to continue the discussion. I don't want people opening new issues for the same thing and would rather keep the discussion in one place. |
@mandolyte asked on #26:
I have read through the go2 generics proposal. While there are definitely some good ideas in there, I'm not the biggest fan of the proposed syntax. I'm not planning to switch Fo to the proposed syntax at this time, especially since the proposal could change. Once the go2 generics proposal(s) become more mature, it is probably worth taking another look. |
@zenhack had this to say on #28 Syntactic ambiguity in generic type declarations:
|
IMO it would be easier to read code which uses < and > instead of [ and ]. Have you considered it during the design? What is the reason behind the current choice?
My two arguments for < and >:
(Really cool experiment btw!)
The text was updated successfully, but these errors were encountered: