[go-nuts] Re: A proof-of-concept implementation of my generics proposal for Go

2019-06-27 Thread Ben Hoyt
I really, really like this. I liked the original proposal, but using the 
"type" keyword seems very natural. And I like the 80/20 constraints thing 
with eq/ord/num. Good work -- I hope this gets turned into an official 
proposal and debated.

-Ben


On Thursday, June 27, 2019 at 10:29:03 AM UTC-4, Michal Strba wrote:
>
> Hey everybody!
>
> A few weeks ago, I posted about my proposal for generics in Go 2. You can 
> find it here. 
> 
>
> Today, I finished a proof-of-concept implementation. It was a lot of fun 
> and I learned a lot about the internals of Go.
>
> The implementation is a program that takes a Go file that uses generics 
> and translates it to a regular Go file that you can run.
>
> Try it out here :) 
>
> I'm looking forwad to all your feedback!
>
> Michal Štrba
>

-- 
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/199bad6c-ed62-44a6-960b-86503242537a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: A proof-of-concept implementation of my generics proposal for Go

2019-06-27 Thread Randall O'Reilly
I also like this proposal, and have a related proposal with a somewhat 
different syntax that is even simpler and is essentially identical to existing 
Go code, just with “Generic Native Types” (GNT).  Here’s a couple of 
side-by-side comparisons:

///
// Min

Michal’s:

func Min(x, y type T ord) T {
if x < y {
return x
}
return y
}

GNT:

func Min(x, y number) type(x) {
…
}

///
// SyncMap

Michal’s:

type SyncMap(type K eq, type V) struct {
mu sync.Mutex
m  map[K]V
}

func (sm *SyncMap(type K eq, type V)) Store(key K, value V) {
sm.mu.Lock()
sm.m[key] = value
sm.mu.Unlock()
}

GNT:

type SyncMap struct interface {
mu sync.RWMutex
m  map   // a generic map
}

func (m *SyncMap) Store(k key(m.Map), v elem(m.Map)) {
…
}

A struct interface is like an interface, specialized for struct -- any struct 
with the specified fields gets the generic methods, instantiated for the 
concrete type, e.g.,:

// MySyncMap instantiates the SyncMap struct interface...
type MySyncMap struct {
mu sync.RWMutex
m  map[string]string
}

Here’s a significantly improved version of the proposal originally posted a few 
weeks ago:
https://gist.github.com/rcoreilly/bfbee2add03c76ada82810423d81e53d  This 
proposal also specifies a complete set of *fixed* “contracts” that are 
isomorphic to the existing native types, so it might appeal to people who 
prefer more explicit semantics for the generic args, compared to more generic 
generics.  Cheers,

- Randy

> On Jun 27, 2019, at 8:13 PM, Ben Hoyt  wrote:
> 
> I really, really like this. I liked the original proposal, but using the 
> "type" keyword seems very natural. And I like the 80/20 constraints thing 
> with eq/ord/num. Good work -- I hope this gets turned into an official 
> proposal and debated.
> 
> -Ben
> 
> 
> On Thursday, June 27, 2019 at 10:29:03 AM UTC-4, Michal Strba wrote:
> Hey everybody!
> 
> A few weeks ago, I posted about my proposal for generics in Go 2. You can 
> find it here.
> 
> Today, I finished a proof-of-concept implementation. It was a lot of fun and 
> I learned a lot about the internals of Go.
> 
> The implementation is a program that takes a Go file that uses generics and 
> translates it to a regular Go file that you can run.
> 
> Try it out here :)
> 
> I'm looking forwad to all your feedback!
> 
> Michal Štrba
> 
> -- 
> 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/199bad6c-ed62-44a6-960b-86503242537a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/655EEB98-6928-48E9-84C4-24C259660E7D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: A proof-of-concept implementation of my generics proposal for Go

2019-06-30 Thread Michal Strba
I fixed the importing issues people were having with version of Go newer
than 1.10.

If you haven't tried the generics tool yet and you're interested, now it
should work for you!

It's a tool that takes a Go file which uses generics and translates it into
a regular Go code that you can run. It also does full type-checking of the
generic code.

On Fri, Jun 28, 2019, 05:14 Randall O'Reilly  wrote:

> I also like this proposal, and have a related proposal with a somewhat
> different syntax that is even simpler and is essentially identical to
> existing Go code, just with “Generic Native Types” (GNT).  Here’s a couple
> of side-by-side comparisons:
>
> ///
> // Min
>
> Michal’s:
>
> func Min(x, y type T ord) T {
> if x < y {
> return x
> }
> return y
> }
>
> GNT:
>
> func Min(x, y number) type(x) {
> …
> }
>
> ///
> // SyncMap
>
> Michal’s:
>
> type SyncMap(type K eq, type V) struct {
> mu sync.Mutex
> m  map[K]V
> }
>
> func (sm *SyncMap(type K eq, type V)) Store(key K, value V) {
> sm.mu.Lock()
> sm.m[key] = value
> sm.mu.Unlock()
> }
>
> GNT:
>
> type SyncMap struct interface {
> mu sync.RWMutex
> m  map   // a generic map
> }
>
> func (m *SyncMap) Store(k key(m.Map), v elem(m.Map)) {
> …
> }
>
> A struct interface is like an interface, specialized for struct -- any
> struct with the specified fields gets the generic methods, instantiated for
> the concrete type, e.g.,:
>
> // MySyncMap instantiates the SyncMap struct interface...
> type MySyncMap struct {
> mu sync.RWMutex
> m  map[string]string
> }
>
> Here’s a significantly improved version of the proposal originally posted
> a few weeks ago:
> https://gist.github.com/rcoreilly/bfbee2add03c76ada82810423d81e53d  This
> proposal also specifies a complete set of *fixed* “contracts” that are
> isomorphic to the existing native types, so it might appeal to people who
> prefer more explicit semantics for the generic args, compared to more
> generic generics.  Cheers,
>
> - Randy
>
> > On Jun 27, 2019, at 8:13 PM, Ben Hoyt  wrote:
> >
> > I really, really like this. I liked the original proposal, but using the
> "type" keyword seems very natural. And I like the 80/20 constraints thing
> with eq/ord/num. Good work -- I hope this gets turned into an official
> proposal and debated.
> >
> > -Ben
> >
> >
> > On Thursday, June 27, 2019 at 10:29:03 AM UTC-4, Michal Strba wrote:
> > Hey everybody!
> >
> > A few weeks ago, I posted about my proposal for generics in Go 2. You
> can find it here.
> >
> > Today, I finished a proof-of-concept implementation. It was a lot of fun
> and I learned a lot about the internals of Go.
> >
> > The implementation is a program that takes a Go file that uses generics
> and translates it to a regular Go file that you can run.
> >
> > Try it out here :)
> >
> > I'm looking forwad to all your feedback!
> >
> > Michal Štrba
> >
> > --
> > 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/199bad6c-ed62-44a6-960b-86503242537a%40googlegroups.com
> .
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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/655EEB98-6928-48E9-84C4-24C259660E7D%40gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAO6k0uv%2BCpg%2BLBVb9SgM8-pF8D_DqqjjJcvMA3LKQmyjGu%2BfbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.