[go-nuts] Re: mark pointer methods on interface type definitiion, not function?

2020-06-23 Thread Anderson Queiroz
I see your point, but the interfaces do not deal with the implementation details, they only specify a behaviour. In your proposal the interface definition would constrain how it can be implemented. Whoever is implementing the interface is responsible for the constraints related to the implement

Re: [go-nuts] [Generics] Concise generics with package level types

2020-06-23 Thread b97tsk
My code shows that returning a generic function might be desirable. The Filter function in my code is as follows: func Filter( type T interface{}, Source Observable(T), )(pred func(T) bool) Operator(T,

Re: [go-nuts] How I can translate this shell command to golang code?

2020-06-23 Thread Franco Marchesini
Yes, this is better. Thanks func main() { cmd := exec.Command("dmtxwrite", "-s", "16x48", "-o", "image2.png") cmd.Stdin = strings.NewReader("123456") if err := cmd.Run(); err != nil { panic(err.Error()) } } Il giorno lunedì 22 giugno 2020 18:19:36 UTC+2, Bakul Shah ha scritto: > > You can

[go-nuts] [generics] Rational for generic methods

2020-06-23 Thread firelizzard
Under "No parameterized methods" , the design document states: In Go, one of the main roles of methods is to permit types to implement > interfaces. It is not clear whether it

Re: [go-nuts] [runtime] gostring question

2020-06-23 Thread Kurtis Rader
On Tue, Jun 23, 2020 at 5:32 PM Bill Morgan wrote: > I'm a C programmer so maybe this is a dumb question but, why does this > code in runtime/gostring.go allocate (rawstring) then copy data (memmove) > instead of just making the stringStruct.str point at the incoming data? > i.e. copy the pointer

[go-nuts] Re: [runtime] gostring question

2020-06-23 Thread Bill Morgan
On Tuesday, June 23, 2020 at 7:32:56 PM UTC-5, Bill Morgan wrote: > > I'm a C programmer so maybe this is a dumb question but, why does this > code in runtime/gostring.go allocate (rawstring) then copy data (memmove) > instead of just making the stringStruct.str point at the incoming data? > i

Re: [go-nuts] [generics] type constraint for structs

2020-06-23 Thread Ian Lance Taylor
On Mon, Jun 22, 2020 at 7:08 PM Pee Jai wrote: > > I can't find a way to constrain for just structs. I don't want primitives. The design draft doesn't provide any mechanism for a type constraint to match any arbitrary struct type, and not any other kind of type. But it's not clear why that would

[go-nuts] [runtime] gostring question

2020-06-23 Thread Bill Morgan
I'm a C programmer so maybe this is a dumb question but, why does this code in runtime/gostring.go allocate (rawstring) then copy data (memmove) instead of just making the stringStruct.str point at the incoming data? i.e. copy the pointer instead of allocating+copying data. func gostring(p *by

Re: [go-nuts] [runtime] Scheduling overhead incurred by the runtime

2020-06-23 Thread Robert Engels
You need to keep the routines “hot” - use polling design... > On Jun 23, 2020, at 11:33 AM, Deepak Sirone wrote: > >  > I have a benchmark (process A) which launches another process (process B) and > the two send messages back and forth through a couple of sockets, one for > sending and the o

Re: [go-nuts] Re: [generics] Type lists should be usable in any interface

2020-06-23 Thread 'Bryan C. Mills' via golang-nuts
My brain was stuck on subtyping yesterday, and when I thought about how subtyping relates to type-list interfaces I realized that they could be made more orthogonal — and more like existing interface types, more useful as sum types, and perhaps even more amenable to specialization via type-switches

Re: [go-nuts] Re: [generics] how to constraint a type must be a map or a slice?

2020-06-23 Thread Ian Lance Taylor
On Tue, Jun 23, 2020 at 8:34 AM T L wrote: > > On Monday, June 22, 2020 at 1:25:33 PM UTC-4, Ian Lance Taylor wrote: >> >> On Mon, Jun 22, 2020 at 8:49 AM T L wrote: >> > >> > One example is the above Print function example. >> > Another example I current get is to iterate and print >> > all the

Re: [go-nuts] [Generics] Concise generics with package level types

2020-06-23 Thread roger peppe
On Tue, 23 Jun 2020 at 17:33, wrote: > Imagine the following function definition, under the current proposal (I > believe this is correct): > > > func (s MyMap(K, V)) DoSomething(k K, v V) (func(type K Hashable) (k K) (V, > error)) {...} > > I don't think that's quite right. You can't have funct

[go-nuts] Re: [Generics] Concise generics with package level types

2020-06-23 Thread haskell_mustard via golang-nuts
Why not put type parameters on packages? https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#why-not-put-type-parameters-on-packages -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this

Re: [go-nuts] What is empty or nil interface (e.g. interface{})

2020-06-23 Thread Sam Whited
The Go tour has a section on this that might be helpful: https://tour.golang.org/methods/14 It matches any type, and should be avoided at all costs unless you really know what you're doing. It sounds great, but it will probably hurt you unless you have a deeper understanding of writing good Go cod

[go-nuts] Re: [generics] Thank you Go team

2020-06-23 Thread ffm2002
Also big +1 from my side and kudos to Ian for always answering to this storm of objections and suggestions with patience and objectiveness Am Freitag, 19. Juni 2020 04:17:16 UTC+2 schrieb Michael Jones: > > I doubt this will help, but I have to try... > > Really smart and accomplished people have

Re: [go-nuts] [generics] is generics with constrain needed ?

2020-06-23 Thread teeling . sean
Instead of doing the implicit conversion to the interface, why not relax the constraint and allow anything that implements the interface? On Wednesday, June 17, 2020 at 1:37:35 AM UTC-7, David Anderson wrote: > > The non-generic form _only_ accepts an argument of type []Stringer. If you > have a

[go-nuts] OAuth2 Endpoint for Google Updated

2020-06-23 Thread bwj . johnson
It looks like the endpoint for authorization for OAuth2 for google is: https://pkg.go.dev/golang.org/x/oauth2/google?tab=doc#pkg-variables var Endpoint = oauth2 .Endpoint { AuthURL:

[go-nuts] [runtime] Scheduling overhead incurred by the runtime

2020-06-23 Thread Deepak Sirone
I have a benchmark (process A) which launches another process (process B) and the two send messages back and forth through a couple of sockets, one for sending and the other for receiving. Both the processes have two go-routines for handling the sending and the receiving side. Process A sends

[go-nuts] What is empty or nil interface (e.g. interface{})

2020-06-23 Thread netconnect . mary
I see this occasionally used as an argument? What's the benefit? Thanks -- 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.

[go-nuts] [Generics] Concise generics with package level types

2020-06-23 Thread teeling . sean
Imagine the following function definition, under the current proposal (I believe this is correct): func (s MyMap(K, V)) DoSomething(k K, v V) (func(type K Hashable) (k K) (V, error)) {...} At least for me, the above takes a while for me to grok. In my opinion the current proposed syntax gets

Re: [go-nuts] Re: [generics] is generics with constrain needed ?

2020-06-23 Thread Ankur Agarwal
Sorry, i wasn't very clear in my first post. 1. There's no implicit conversion between a value type and an interface, and constraints would make this possible, but i feel that it's at the expense of making the language unnecessarily complicated. Can we not just think through our design of our a

Re: [go-nuts] [generics] constraint for nillable types?

2020-06-23 Thread jimmy frasche
One way is https://github.com/golang/go/issues/26842 which is to provide some mechanism to compare any value with its type's zero value (either with a universal zero value or something like isZero(v)). That removes all the special cases so you could use it even without any constraints On Tue, Jun

Re: [go-nuts] Re: [generics] how to constraint a type must be a map or a slice?

2020-06-23 Thread T L
On Monday, June 22, 2020 at 1:25:33 PM UTC-4, Ian Lance Taylor wrote: > > On Mon, Jun 22, 2020 at 8:49 AM T L > > wrote: > > > > One example is the above Print function example. > > Another example I current get is to iterate and print > > all the key and values of a container in a current f

Re: [go-nuts] Go has eliminated most of my off-by-one errors except 0... I mean 1.

2020-06-23 Thread C Banning
Well, I imagine there's only a few types in any code where the logic would require retrieving the "last" member of a list or array. Something like the following could address that and be more performant than using reflection - https://play.golang.org/p/XTbuf7RegF2. On Sunday, June 14, 2020 at 9

Re: [go-nuts] Re: [generics] is generics with constrain needed ?

2020-06-23 Thread Ankur Agarwal
Sorry, I wasn't clear in my last post. > 1. There's no implicit conversion between a value type and an interface, and constraints would make this possible, but i feel that it's at the expense of making the language unnecessarily complicated. Can we not just think through our design of our appli

Re: [go-nuts] Why not use F in generic?

2020-06-23 Thread roger peppe
On Tue, 23 Jun 2020 at 03:04, Ian Lance Taylor wrote: > On Mon, Jun 22, 2020 at 6:19 PM 移库海牙客 wrote: > > > > I agree the syntax should be more readable and easier to understand. But > I think the current syntax is less readable. > > For example: > > > > type I2 interface { > > (I1(int)) > > } >

Re: [go-nuts] Weird benchmark results for seemingly identical functions

2020-06-23 Thread Yonatan Ben-Nes
So I'm probably missing something obvious again but the fact that the loops were checking different/inverse conditions should not have cause the append line to cost 300k ns/op. I'm referring to the line `lcp = append(lcp, 0)` which appear at the start of both of the functions, when I'm running

Re: [go-nuts] [generics] constraint for nillable types?

2020-06-23 Thread roger peppe
FWIW I also came across this issue recently in a different context and similarly wondered if a nillable constraint might be a good idea. There is a kinda workaround although you won't like it :) https://go2goplay.golang.org/p/-nDAUVYWuxo On Tue, 23 Jun 2020 at 05:43, 'Bryan C. Mills' via golan