On Sun, Mar 21, 2021 at 1:02 PM Martin Leiser <leiser.1...@gmail.com> wrote:
>
> I think so. But How? Remember we need to do two things:
>
>     - A way to define type parameters.
>
>     - A way to bind the type parameters to concrete types at compile time

Thanks for the note.

I think that a generics proposal needs to do three things.  The third
is that it needs to describe which operations are permitted for a type
parameter.


> But after we named it "ElementType" we can get a hold of it and bind it in 
> the package we intend to use e.G. a "list of strings":
>
>     import "container/list"  type ElementType string

This general kind of idea has been suggested quite a few times before.
Here are a few examples:

https://gist.github.com/PeterRK/41d4d3f54b8db55cd616403fd5a389f3
https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
https://groups.google.com/g/golang-nuts/c/xKYXZpsWHus/m/SS4FKMBEAQAJ

There are others.


> Last features. If you need two different bindings in one package, say a list 
> of string and a list of int you may use:
>
>     import "container/list" intlist  type ElementType = int
>
>     import "container/list" stringlist type ElementType = string

What if I want to have a list of lists of strings?

What if I want to have a list of some unexported type that I defined
in this package?  That seems to require interweaving type definitions
and imports in ways that the language does not currently support.

With this proposal, how can I write a min function that works for any
integer type, including a user-defined integer type?  What happens if
I try to import a package that defines that Min function but I set the
argument type to some that does not support the < operator?

Thanks again.

Ian

-- 
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/CAOyqgcURm0uCGWPDQiyX_2FfGAon_snXKjn%3DmA_%3D1W1ScFc1Wg%40mail.gmail.com.

Reply via email to