Re: [go-nuts] [generics] why struct fields-based constraints were banned?

2020-06-17 Thread 'Bryan C. Mills' via golang-nuts
I could imagine a new kind of interface type specifying fields (not just methods), with the offsets of the corresponding fields in the concrete type stored in the interface's type descriptor. (I think such a feature would be orthogonal to the current design draft, and could be proposed

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

2020-06-17 Thread 'Bryan C. Mills' via golang-nuts
On Wednesday, June 17, 2020 at 12:08:59 AM UTC-4 Ian Lance Taylor wrote: > On Tue, Jun 16, 2020 at 9:04 PM Xie Zhenye wrote: > > > > I agree. constraint is different from normal interface. It's better to > use type SomeConstraint constraint {} than type SomeConstraint interface {} > > That

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

2020-06-17 Thread Miguel Angel Rivera Notararigo
Oh, it was a FAQ haha sorry about that and thanks Tyler and Ian :D -- 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

[go-nuts] Re: [generics] Why is constraint optional?

2020-06-17 Thread Andrey Tcherepanov
Wouldn't it be nice to have just func Foo(type T1, type T2 Bar) (type as keyword splitting it into 2 type declarations) On Wednesday, June 17, 2020 at 5:50:47 AM UTC-6, Brian Candler wrote: > > Consider a generic where you want T1 unconstrained but T2 constrained. If > you write > > func

Re: [go-nuts] [generics] Why is constraint optional?

2020-06-17 Thread eric fang
> > It seems annoying to force > everyone to write interface{} all the time when it is normally not > needed. > I agree, omitting interface{} should not cause much trouble to the parser. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

[go-nuts] [generics] avoid dummy getter by interface with fields

2020-06-17 Thread nvcnvn
Since Go will need to modify interface with new type list anyway. Is it good if we can do this: ``` type Weighter interface { Weight int } func CompareWeight(type T Weighter) (a, b T) bool { return a.Weight < b.Weight } ``` Instead of: ``` type Weighter interface { GetWeight() int

Re: [go-nuts] Awkwardness around built in containers and user containers

2020-06-17 Thread David Riley
On Jun 17, 2020, at 8:45 PM, Ian Lance Taylor wrote: > > On Wed, Jun 17, 2020 at 9:35 AM wrote: >> >> How do I write a function that can take any container? Either a built in >> container or a user defined structure? Java is awkward when deciding to >> accept arrays or the List type — is go

[go-nuts] Re: [generics] (again). Type inference is somewhat weak

2020-06-17 Thread Denis Cheremisov
Better example. A method to request for exacly one element from the gRPC bistream. A thing that is frequently needed when there're lots of bistream gRPC methods. https://go2goplay.golang.org/p/RQEyhRRQb0p IRL I would need to call it as resp, err := proto.ReadOne(service.Service_MethodClient,

Re: [go-nuts] Regarding time.NewTicker() and monotonic time

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 7:24 AM Konstantin Khomoutov wrote: > > On Wed, Jun 10, 2020 at 04:03:36PM -0700, Ian Lance Taylor wrote: > > [...] > > In the current implementations of Go, Tickers are not garbage > > collected. They run until they are stopped. So if you don't stop a > > ticker, it

Re: [go-nuts] [generics] Why is constraint optional?

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 4:19 AM Hal wrote: > > "If a constraint is specified for any type parameter, every type parameter > must have a constraint. If some type parameters need a constraint and some do > not, those that do not should have a constraint of interface{}." > > "interface{}" equals

Re: [go-nuts] [generics] Replace () with <> or other character

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 9:36 AM Charles Crete wrote: > > Based on the new proposal, having the type parameters as () seems very > confusing, as now 3 things in a row use (): > - Type parameters > - Function parameters/arguments > - Return tuple > > This results in code like (from the draft): >

Re: [go-nuts] [generics]Use "<>" to declare template would be better than "()"

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 9:35 AM hao luo wrote: > > The creator: > > Hi, I am extremely interested in and eager for golang's generics, and I have > read the updated draft. > https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#acknowledgements > > I think

Re: [go-nuts] Awkwardness around built in containers and user containers

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 9:35 AM wrote: > > How do I write a function that can take any container? Either a built in > container or a user defined structure? Java is awkward when deciding to > accept arrays or the List type — is go fated to repeat this awkwardness? It is as you fear: Go does

Re: [go-nuts] [generics] Type parameter inference in generic struct literals

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 9:35 AM tomas via golang-nuts wrote: > > Could type parameters be omitted when they could be inferred in struct > literals? https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#type-inference-for-composite-literals Ian -- You

Re: [go-nuts] [generics] Simplification: Methods refer to original type parameters instead of re-specifying each time

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 5:18 PM Randall O'Reilly wrote: > > Good point! > > I can think of 2 possible (non-mutex) solutions: > > * Use an explicit type expression to refer to the type: `type(ms.T)` and the > field is just `ms.T` > > * Within the method scope, make `T` a valid type name, so you

Re: [go-nuts] [generics] Generic functions calls little confusing to readers

2020-06-17 Thread Randall O'Reilly
Here's a proposal for a syntactic modification to the draft proposal that removes explicit type parameters from functions, and just uses generic types directly (e.g., the new interface types): https://github.com/golang/go/issues/39669 This would go a long way toward simplifying the syntax and

Re: [go-nuts] [generics] why struct fields-based constraints were banned?

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 10:05 AM Denis Cheremisov wrote: > > I can't get why struct based constraints were banned. struct is a kind of > types in Go and a wish to only allow them having some field is valid. I'm not sure I would say that they were banned, it's just that we haven't seen a good

Re: [go-nuts] [generics] Simplification: Methods refer to original type parameters instead of re-specifying each time

2020-06-17 Thread Randall O'Reilly
Good point! I can think of 2 possible (non-mutex) solutions: * Use an explicit type expression to refer to the type: `type(ms.T)` and the field is just `ms.T` * Within the method scope, make `T` a valid type name, so you can just use `T` directly -- this might even be preferable overall as it

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

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 10:55 AM Tyler Compton wrote: > The reason why implicit conversions from []Foo to []Stringer isn't > supported is because Foo and Stringer have different in-memory > representations. Converting from a slice of one to a slice of another would > be more expensive than one

[go-nuts] Re: [generics] Generic functions calls little confusing to readers

2020-06-17 Thread google via golang-nuts
On Wednesday, 17 June 2020 07:54:02 UTC+10, Alexander Morozov wrote: > > I wonder how could we avoid this confusion (apart from using different > brackets :)). > I know the brackets discussion has been had before, and that there are some technical, and non-technical reasons why parentheses were

Re: [go-nuts] Re: go scheduler tracing

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 4:40 PM envee wrote: > > Hi Robert, It is in my first post in this thread. Basically, I want to know > why all my logical processors are not being used in my program. Thanks. New goroutines are added to the run queue for the P that creates them. When a P has nothing to

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 4:33 PM jimmy frasche wrote: > > If I merge the two examples I still get an error > https://go2goplay.golang.org/p/TNYLDLokGCQ > > prog.go2:21:2: int does not satisfy Z (int not found in ⊥) I think that may be a bug in the type checker, which may not be quite updated to

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread jimmy frasche
I think that second error is a bug. I would expect that case to be the same as if I wrote a type list that was just int (and hence not the empty type list). On Wed, Jun 17, 2020 at 4:33 PM jimmy frasche wrote: > > If I merge the two examples I still get an error >

Re: [go-nuts] Re: go scheduler tracing

2020-06-17 Thread envee
Hi Robert, It is in my first post in this thread. Basically, I want to know why all my logical processors are not being used in my program. Thanks. On Thursday, 18 June 2020 07:24:40 UTC+10, Robert Engels wrote: > > What is the question? > > On Jun 17, 2020, at 4:06 PM, envee > > wrote: > >

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread jimmy frasche
If I merge the two examples I still get an error https://go2goplay.golang.org/p/TNYLDLokGCQ prog.go2:21:2: int does not satisfy Z (int not found in ⊥) On Wed, Jun 17, 2020 at 4:24 PM Ian Lance Taylor wrote: > > On Wed, Jun 17, 2020 at 3:52 PM jimmy frasche wrote: > > > > The only case I mean

[go-nuts] Re: [generics] gRPC bistream quantization

2020-06-17 Thread Denis Cheremisov
Thank you -- 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

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 3:52 PM jimmy frasche wrote: > > The only case I mean is when the intersection of the type lists is ∅. > That's easy to check and always wrong afaict. Unfortunately I don't think it's that simple. type MyInt int type I1 interface { type int } type I2 interface {

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread jimmy frasche
The only case I mean is when the intersection of the type lists is ∅. That's easy to check and always wrong afaict. On Wed, Jun 17, 2020 at 3:47 PM Ian Lance Taylor wrote: > > On Wed, Jun 17, 2020 at 1:09 PM jimmy frasche wrote: > > > > This isn't a bug per se, but I can file one if requested.

Re: [go-nuts] [generics] the empty type list

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 1:09 PM jimmy frasche wrote: > > This isn't a bug per se, but I can file one if requested. > > https://go2goplay.golang.org/p/AWynhg6ya7h > > Since embedding interfaces with type lists uses the intersection of > the items in the type list, it's possible to create an

Re: [go-nuts] [generics] A Channel of a Generic Structure

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 2:37 PM Harald Weidner wrote: > > > Here is the playground: https://go2goplay.golang.org/p/CVvUuNJVX-M > > I am unable to make this example to compile. > > This one compiles: > https://go2goplay.golang.org/p/2rmaCymukdv Thanks. I'm not sure why those parentheses are

[go-nuts] Re: [generics] gRPC bistream quantization

2020-06-17 Thread andrew . ekstedt
On Wednesday, June 17, 2020 at 2:00:00 PM UTC-7, Denis Cheremisov wrote: > > Another question about generics, a HOWTODO one: I am bored to death > writing methods what would send one request and get one response from a > gRPC bistream. Decided to try a draft 2 against a generic approach to the

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 9:58 AM Denis Cheremisov wrote: > > IMO a groups of constraints are horrible with interfaces > > type CommonResponse(type E) interface { > GetError() E > } > > type CommonError interface { > GetCode() int32 > } > > func IsOK(type R CommonResponse(E), E

Re: [go-nuts] [generics] A Channel of a Generic Structure

2020-06-17 Thread Harald Weidner
Hello, > Here is the playground: https://go2goplay.golang.org/p/CVvUuNJVX-M > I am unable to make this example to compile. This one compiles: https://go2goplay.golang.org/p/2rmaCymukdv Regards, Harald -- You received this message because you are subscribed to the Google Groups "golang-nuts"

Re: [go-nuts] Re: go scheduler tracing

2020-06-17 Thread Robert Engels
What is the question? > On Jun 17, 2020, at 4:06 PM, envee wrote: > > Hi, Is anyone able to help me here ? > Here is a (simplified) snippet of the code, in case it helps answering my > query. I basically create a goroutine for every input file (assume max 8) and > then wait for processing of

[go-nuts] Re: go scheduler tracing

2020-06-17 Thread envee
Hi, Is anyone able to help me here ? Here is a (simplified) snippet of the code, in case it helps answering my query. I basically create a goroutine for every input file (assume max 8) and then wait for processing of all files to finish. Each goroutine processes a line within the file and then

[go-nuts] [generics] gRPC bistream quantization

2020-06-17 Thread Denis Cheremisov
Another question about generics, a HOWTODO one: I am bored to death writing methods what would send one request and get one response from a gRPC bistream. Decided to try a draft 2 against a generic approach to the task. My final attempt which I still can't compile:

[go-nuts] [generics] the empty type list

2020-06-17 Thread jimmy frasche
This isn't a bug per se, but I can file one if requested. https://go2goplay.golang.org/p/AWynhg6ya7h Since embedding interfaces with type lists uses the intersection of the items in the type list, it's possible to create an interface that cannot be satisfied by any type. Currently this does not

Re: [go-nuts] compiler RFE

2020-06-17 Thread Ian Lance Taylor
On Wed, Jun 17, 2020 at 12:16 PM wrote: > > I remember using mainframe FORTRAN compilers where the compiler would print > out a page of symbol cross references. > > For each symbol or function there would listed the line where it was defined > and then line numbers where it was used/referenced.

[go-nuts] [generics] A Channel of a Generic Structure

2020-06-17 Thread teivah . dev
Hello all, I'm working on implementing generics on a big container projet. So far, everything was good except for this very case: type Foo(type T) struct { v int } func (_ *Foo(T)) bar() int { elem := <-make(chan Foo(T)) return elem.v } *Foo* being a generic structure, I have a

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread Я
> if you find it more readable not only readable. I still can't get why they banned constraints on structs having some fields of certain type. With contracts they are easy to allow: contract NameField(T) { T Name string } and there's no hope with interfaces ср, 17 июн. 2020 г. в 21:37,

[go-nuts] compiler RFE

2020-06-17 Thread hardconnect . joe
I remember using mainframe FORTRAN compilers where the compiler would print out a page of symbol cross references. For each symbol or function there would listed the line where it was defined and then line numbers where it was used/referenced. Something similar would be useful for GO. Printing

[go-nuts] Re: [generics] bring contracts back

2020-06-17 Thread Denis Cheremisov
oops, an infitie loop in the As implementation, now the right one: https://go2goplay.golang.org/p/5NnZBnmIC96 среда, 17 июня 2020 г., 21:55:52 UTC+3 пользователь Denis Cheremisov написал: > > There's an advantage though, for rather narrow cases though: reuse of > interfaces: > >

[go-nuts] Re: [generics] bring contracts back

2020-06-17 Thread Denis Cheremisov
There's an advantage though, for rather narrow cases though: reuse of interfaces: https://go2goplay.golang.org/p/HJr3QIzgQuX среда, 17 июня 2020 г., 19:58:08 UTC+3 пользователь Denis Cheremisov написал: > > IMO a groups of constraints are horrible with interfaces > > type CommonResponse(type

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread 'Axel Wagner' via golang-nuts
Ah sorry, I misunderstood. Please disregard :) On Wed, Jun 17, 2020, 20:36 Axel Wagner wrote: > You can always combine multiple interface constraints: > > type ConstraintA(type A) interface { > Foo() A > } > > type ConstraintB(type B) interface { > Bar() B > } > > type

Re: [go-nuts] [generics] bring contracts back

2020-06-17 Thread 'Axel Wagner' via golang-nuts
You can always combine multiple interface constraints: type ConstraintA(type A) interface { Foo() A } type ConstraintB(type B) interface { Bar() B } type CombinedConstraint(type A, B) interface { (ConstraintA(A)) (ConstraintB(B)) } func F(type A, B CombinedConstraint(A, B))

Re: [go-nuts] [generics] Simplification: Methods refer to original type parameters instead of re-specifying each time

2020-06-17 Thread Tyler Compton
I think this syntax could get confusing when embedded fields is added to the mix: type MyStruct(type T) struct { T } func (ms *MyStruct) MyMethod(t ms.T) { ms.T = t } In this example. ms.T means two very different things depending on where they are used. On Wed, Jun 17, 2020 at 3:45

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

2020-06-17 Thread Tyler Compton
The reason why implicit conversions from []Foo to []Stringer isn't supported is because Foo and Stringer have different in-memory representations. Converting from a slice of one to a slice of another would be more expensive than one would expect an implicit conversion to be. At least, this is my

Re: [go-nuts] Re: [generics] Generic functions calls little confusing to readers

2020-06-17 Thread Harald Weidner
Hello, > There is an existing case which doesn't seem to bother many people: > > foo.Bar() > > Is this calling function Bar in package foo, or method Bar on variable > foo? It could also be a call of a function within the struct value foo. foo.Bar(baz) can have at least four meanings: 1.

[go-nuts] [generics] why struct fields-based constraints were banned?

2020-06-17 Thread Denis Cheremisov
I can't get why struct based constraints were banned. struct is a kind of types in Go and a wish to only allow them having some field is valid. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

[go-nuts] [generics] bring contracts back

2020-06-17 Thread Denis Cheremisov
IMO a groups of constraints are horrible with interfaces type CommonResponse(type E) interface { GetError() E } type CommonError interface { GetCode() int32 } func IsOK(type R CommonResponse(E), E CommonError)(r R) bool { switch r.GetError().GetCode() { case 0, 200, 201:

Re: [go-nuts] [generics] another parsing ambiguity

2020-06-17 Thread Gert
Thanks, can you maybe at the complete working code snippet in your issue too ``` type R(type T) struct{} func F(type T)() { _ = func() (_ R(T)) { return R(T){} } } ``` I think it's not trivial code even after reading the issue what your solution was to the problem. -- You received this

Re: [go-nuts] [generics] Replace () with <> or other character

2020-06-17 Thread Dimas Prawira
more and more like Java.. BR On Wed, Jun 17, 2020 at 11:36 PM Charles Crete wrote: > Based on the new proposal, having the type parameters as () seems very > confusing, as now 3 things in a row use (): > - Type parameters > - Function parameters/arguments > - Return tuple > > This results in

[go-nuts] Re: [generics]Use "<>" to declare template would be better than "()"

2020-06-17 Thread Denis Cheremisov
Better for who? You? I would to love to see `[]` instead of `()`, but `<>` are horrible to read IMO. среда, 17 июня 2020 г., 19:36:09 UTC+3 пользователь hao luo написал: > > The creator: > > Hi, I am extremely interested in and eager for golang's generics, and I > have read the updated draft.

Re: [go-nuts] [generics] Awkwardness interfacing between primitives and structs

2020-06-17 Thread Robert Engels
This is not how it is typically done in Java. You create an immutable List that is backed by the array. No copy required. You will also implement RandonAccess to distinguish from linked lists. Lastly, it doesn’t need to be immutable, and lots of structures like ArrayList are mutable and

[go-nuts] Re: [generics] Replace () with <> or other character

2020-06-17 Thread Denis Cheremisov
> > makes it easier to visual parse > Are you sure? It may be a personal thing, but "visual parsing" of these <<< really annoys me, I would prefer `[]`, but I like `()` more than `<>`. In addition, a good IDE (not that well known overhyped editor on steroids) will highlight these fragments, so

[go-nuts] [generics] (again). Type inference is somewhat weak

2020-06-17 Thread Denis Cheremisov
https://go2goplay.golang.org/p/ObL79WVHDjw Need to write types explicitly although all the info needed is easily accessible: fmt.Println(IsOK(*commonResponse, *commonError)(r)) What I am sure is I will keep using a code generator instead of this monstrosity. -- You received this message

[go-nuts] [generics] Replace () with <> or other character

2020-06-17 Thread Charles Crete
Based on the new proposal, having the type parameters as () seems very confusing, as now 3 things in a row use (): - Type parameters - Function parameters/arguments - Return tuple This results in code like (from the draft): func Stringify(type T Stringer)(s []T) (ret []string) { for _, v :=

[go-nuts] Awkwardness around built in containers and user containers

2020-06-17 Thread hunterlherman
How do I write a function that can take any container? Either a built in container or a user defined structure? Java is awkward when deciding to accept arrays or the List type — is go fated to repeat this awkwardness? -- You received this message because you are subscribed to the Google Groups

[go-nuts] [generics]Use "<>" to declare template would be better than "()"

2020-06-17 Thread hao luo
The creator: Hi, I am extremely interested in and eager for golang's generics, and I have read the updated draft. https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#acknowledgements I think use "<>" to declare template's type would be more appropriate.

[go-nuts] [generics] tiny typo in Map/Reduce/Filter examples

2020-06-17 Thread Mark
At the end of this section where it shows the outputs: ```go floats := slices.Map(s, func(i int) float64 { return float64(i) })// Now float2 is []float64{1.0, 2.0, 3.0}. ``` shouldn't that be: ```go floats := slices.Map(s, func(i int) float64 { return float64(i) })// Now floats is

Re: [go-nuts] Re: How are Go talk slides created?

2020-06-17 Thread ali . kabiri
Could you please explain what the problem was? On Saturday, June 15, 2013 at 11:59:56 PM UTC+2, Frank Blechschmidt wrote: > > I already figured it out thanks to some guys in the Go+ Group :) > > > On Sat, Jun 15, 2013 at 11:52 PM, Dan Kortschak > wrote: > >> First, you don't ned to put the slide

[go-nuts] [generics] Type parameter inference in generic struct literals

2020-06-17 Thread tomas via golang-nuts
Hello all, Could type parameters be omitted when they could be inferred in struct literals? Here's a scenario that doesn't work today (https://go2goplay.golang.org/p/Jt5OGfLePuu) package main import ( "fmt" ) type BinaryTree(type T) struct { Value T Left, Right *BinaryTree(T) } func

[go-nuts] [generics] Awkwardness interfacing between primitives and structs

2020-06-17 Thread Hunter Herman
Suppose I want to write a function over any list like container (histogram, reverse...) how can I? Java requires special code if you want to process arrays — thus most code takes Lists, and accepting an array (eg a vararg) is likely to lead to a copy into a list at some point. Is go fated to

Re: [go-nuts] [generics] another parsing ambiguity

2020-06-17 Thread benjaminjkraft
I've now created an issue here: https://github.com/golang/go/issues/39654. -- 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

Re: [go-nuts] [generics] another parsing ambiguity

2020-06-17 Thread Gert
At Ben did you made a github issue yet for it? Can't seem to find it https://github.com/golang/go/issues?q=is%3Aissue+cmd%2Fgo2go 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

Re: [go-nuts] Generics: More on parens

2020-06-17 Thread Aaron Cannon
Thanks Ian for the reply. I certainly understand wanting to get more experience with the proposed syntax, but I still don't think the trade-offs are worth it. In particular, I remain concerned about the cognitive load of using parens in yet another context, and the (IMHO) unnecessary breaking of

Re: [go-nuts] Regarding time.NewTicker() and monotonic time

2020-06-17 Thread Konstantin Khomoutov
On Wed, Jun 10, 2020 at 04:03:36PM -0700, Ian Lance Taylor wrote: [...] > In the current implementations of Go, Tickers are not garbage > collected. They run until they are stopped. So if you don't stop a > ticker, it will keep ticking until your program exits. > > (It is possible that future

Re: [go-nuts] [generics] Why is constraint optional?

2020-06-17 Thread 'Axel Wagner' via golang-nuts
On Wed, Jun 17, 2020 at 1:19 PM Hal wrote: > * the syntax defining generic function is verbose on purpose (type > keyword), not only for clarification, but also a remind of the cost and > complexity behind generics > I don't know where this idea is from, but it's not accurate. The type keyword

Re: [go-nuts] Re: [generics] Why is constraint optional?

2020-06-17 Thread Brian Candler
Sorry, I understand what you're saying now. I quite like "type T" meaning "any type", but you have a fair point. -- 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

Re: [go-nuts] Re: [generics] Why is constraint optional?

2020-06-17 Thread Hǎiliàng Wáng
Hi Brian, Thanks for your reply but I don’t think you get my point, what I mean is constraint should be always explicitly specified, so we should not support “optional” or “omitted” constraints. On Wed, 17 Jun 2020 at 12:51, Brian Candler wrote: > Consider a generic where you want T1

[go-nuts] Re: [generics] Why is constraint optional?

2020-06-17 Thread Brian Candler
Consider a generic where you want T1 unconstrained but T2 constrained. If you write func Foo(type T1, T2 Bar) then Bar constrains both. Hence the need for func Foo(type T1 interface{}, T2 Bar) -- You received this message because you are subscribed to the Google Groups "golang-nuts"

[go-nuts] generics and absence of ability to specify correlated types

2020-06-17 Thread 'Dan Kortschak' via golang-nuts
Since this has come up again in [1], I would like to re-raise the issue of being able to correlate float and complex types so that a func(float32) complex64/func(float64) complex128-like function can be written generically. This issue was raised in [2] in the last round of generics discussions

[go-nuts] [generics] Why is constraint optional?

2020-06-17 Thread Hal
"If a constraint is specified for any type parameter, every type parameter must have a constraint. If some type parameters need a constraint and some do not, those that do not should have a constraint of interface{}." "interface{}" equals to "Any Type" in the context of generics. So it seems

[go-nuts] [generics] Simplification: Methods refer to original type parameters instead of re-specifying each time

2020-06-17 Thread Randall O'Reilly
You could save a fair amount of typing and eyestrain by not replicating the type params for types, in their methods: type Vector(type T) []T func (v *Vector) Push(x v.T) { *v = append(*v, x) } type Map(type K, V) struct { root*node(K, V) compare func(K, K) int

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

2020-06-17 Thread Miguel Angel Rivera Notararigo
Allowing this implicit conversion would be a bad thing? because it works like generics without any new syntax. Also, I found this a little messy type Ordered interface { type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr,

[go-nuts] Re: [generics] Generic functions calls little confusing to readers

2020-06-17 Thread Brian Candler
Also, type arguments to generic function calls are *optional*: https://go2goplay.golang.org/p/w-q65tL5wh- Therefore, when looking at a foo(bar)(baz), you have to know whether (bar) is a value or a type, which requires scanning the code to find the definition of 'bar' in this scope or nearest

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

2020-06-17 Thread David Anderson
The non-generic form _only_ accepts an argument of type []Stringer. If you have a []Foo, where Foo implements Stringer, that's not good enough. You will have to construct a []Stringer explicitly, and copy each Foo into that []Stringer. This is a fairly common gotcha with Go, where folks expect the

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

2020-06-17 Thread Christophe Meessen
Reading the document "Type parameters - Draft desing" of June 16, 2020 (https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md), I wonder if these two following function definitions are not equivalent and thus interchangeable func Stringify(type T

[go-nuts] Re: [generics] slightly surprising syntax for *T methods

2020-06-17 Thread Sebastien Binet
for completeness' sake, there is indeed no need for pointer methods: https://go2goplay.golang.org/p/1WD7WRAmNim (my main point was the gotcha w/ 'func (dec *Decoder(*T)) F()') ‐‐‐ Original Message ‐‐‐ On Wednesday, June 17, 2020 9:08 AM, Sebastien Binet wrote: > hi there, > > I was

[go-nuts] [generics] slightly surprising syntax for *T methods

2020-06-17 Thread Sebastien Binet
hi there, I was playing a bit w/ pointer methods[1] to see how this could be applied to a pet peeve of mine: ensuring at compile-time that, e.g., json.Decoder.Decode takes a pointer to a value: https://go2goplay.golang.org/p/J2Lr5QrkKTj this works: func Decode(type *T)(ptr *T) error {