|
|
Subscribe / Log in / New account

Generics parameter syntax

Generics parameter syntax

Posted Jul 5, 2020 10:06 UTC (Sun) by dezgeg (subscriber, #92243)
In reply to: Generics parameter syntax by davecb
Parent article: Generics for Go

In some languages (Haskell comes to mind, also Erlang I think) case-sensitivity is used to enforce this kind of problems without requiring a symbol table in the parser. In Haskell, uppercase names always refer to types or type constructors; and lowercase names always refer to variables or type parameters. Sadly not many new languages seem to take use of this as I personally find it quite elegant.


to post comments

Generics parameter syntax

Posted Jul 5, 2020 19:11 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link]

Go uses upper case names for exported symbols and lower-case names for package-local ones.

Generics parameter syntax

Posted Jul 5, 2020 22:23 UTC (Sun) by dtlin (subscriber, #36537) [Link] (2 responses)

In Haskell, types do begin with an upper-case letter or : symbol, but data constructors (which are values) also begin with an upper-case letter or : symbol and type variables begin with a lower-case letter or non-: symbol, so that's not useful for disambiguation.

But only values appear to the left of :: and only types appear to the right of ::, so there's no confusion. Except in import lists, or when -XTypeApplications, -XDataKinds, -XStarIsType, … No angle brackets so it doesn't suffer from C++'s problems though.

Generics parameter syntax

Posted Jul 6, 2020 20:38 UTC (Mon) by dezgeg (subscriber, #92243) [Link] (1 responses)

Haskell was just an example of some other language where caseness of a name matters (but apparently even Go already uses it in other manner). I was thinking about having names starting with Uppercase always refer to types and names starting lowercase be variables. Thus in the v := F<T> example the caseness of F would tell whether the < is the less than operator or the opening bracket of a type parameter.

Generics parameter syntax

Posted Jul 7, 2020 12:19 UTC (Tue) by dtlin (subscriber, #36537) [Link]

It helps for that case, but if you have higher-order kinds, f<t> is also a type, for some appropriate type variables f and t.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds