[go-nuts] Re: are Go generics more like C++ or more like Java?

2022-02-25 Thread Markus Heukelom
Correction: - it must be possible to express that T is comparable (so that you can use map[K]V, were K must be comparable) - it must be possible restrict T to a concrete list of types (f.e. min(a, b T) T must be possible to write) On Friday, February 25, 2022 at 11:13:01 AM UTC+1 Markus

[go-nuts] Re: are Go generics more like C++ or more like Java?

2022-02-25 Thread Markus Heukelom
I think the consensus in the Go community is to refrain from comparing Go language features with other programming languages. Rationale ~: - it is highly contentious - it is very difficult to answer, it's like asking "is purple more blue or more red" - no matter the answer, it will not help you

Re: [go-nuts] pkg.go.dev: navigation index is confusing

2021-09-03 Thread Markus Heukelom
> > @Markus: I normally use browser's search function to get to the function > and it works well with pkg.go.dev too. > > Using the search function only works if you know the name of the function. Very common examples when this doesn't work: Package HTTP: If you vaguely remember a function name,

[go-nuts] pkg.go.dev: navigation index is confusing

2021-09-02 Thread Markus Heukelom
The main issue is that most package functions are not actually listed under "Functions". For example, I wanted to lookup StripPrefix in the http package. I could not find it in the package documentation function index. It was not there. So I looked under Types (maybe I did remember it incorre

[go-nuts] Type assertion: panic: value method time.Time.String called using nil *Time pointer"

2021-06-10 Thread Markus Heukelom
Code: package main import ( "fmt" "time" ) func main() { var my *time.Time var any interface{} any = my stringer, ok := any.(fmt.Stringer) println(ok) // "true", but I expected "false", as the receiver for time.Time.String() is (t time.Time), not (t *time.Time) println(stringer.String()) // "p

[go-nuts] Re: Type parameters syntax... Can it be improved?

2021-03-24 Thread Markus Heukelom
I agree here that there is a lot of repetition in the function definitions of let's say a generic math package: types Numbers { type float32,float64, } func Abs[T Floats](a T) T {} func Sin[T Floats](a T) T {} func Cos[T Floats](a T) T {} etc. (50 orso more?) It feels a bit redundant and

[go-nuts] Re: Is there a final document on generics?

2021-03-17 Thread Markus Heukelom
On Tuesday, March 16, 2021 at 11:27:12 AM UTC+1 Haddock wrote: > > > Therefore I wonder whether it would make sense for the Go core development > team to define a couple of generic interfaces for sets, lists, queues, > maps, etc. that are part of the standard library to prevent some > uncontr

[go-nuts] Re: What's the status/roadmap of geo/s2 library?

2021-01-28 Thread Markus Heukelom
I think your question is answered by s2/geo github page itself (https://github.com/golang/geo): " *In Progress* Files that have some work done, but are probably not complete enough for general use in production code. - CellIndex - A queryable index of CellIDs. etc On Tuesday, January 2

Re: [go-nuts] Re: Generics - please provide real life problems

2021-01-01 Thread Markus Heukelom
On Fri, Jan 1, 2021 at 2:16 PM Axel Wagner wrote: > Hi, > > On Fri, Jan 1, 2021 at 1:41 PM Markus Heukelom > wrote: > >> One thing that comes to mind that is not supported by the current >> proposal is the ability to express that T must be (any) struct. >> &g

Re: [go-nuts] Re: Generics - please provide real life problems

2021-01-01 Thread Markus Heukelom
>> On Thursday, December 31, 2020 at 11:27:06 AM UTC+1 axel.wa...@googlemail.com wrote: >> I don't think the current draft lets us express very powerful invariants. And while I wouldn't really advocate to make that a target, I think it would be interesting to see more discussion of this area -

Re: [go-nuts] Re: Generics, please go away!

2020-12-23 Thread Markus Heukelom
On Tue, Dec 22, 2020 at 9:48 PM Ian Lance Taylor wrote: > On Tue, Dec 22, 2020 at 1:24 AM Markus Heukelom > wrote: > > > > Why not issue a poll on generics, was this ever done? (I could've missed > it, I am only following Go ~2 years). While the community has a vot

[go-nuts] Re: Generics, please go away!

2020-12-22 Thread Markus Heukelom
Why not issue a poll on generics, was this ever done? (I could've missed it, I am only following Go ~2 years). While the community has a vote in accepting/rejecting the current generics proposal, the community was never (really) asked if generics is desired in the first place and especially wh

[go-nuts] Generics and methods on predeclared types

2020-11-10 Thread Markus Heukelom
Currently the predeclared types (int, bool, float32, string, etc) do not have any methods on them. It appears to me that if they would, the generic implementation for math.Min/Max etc could do without 'types' in interfaces (as is currently proposed). For example: type Sortable[T any] interface

[go-nuts] Re: Reduced error handling noice

2020-10-09 Thread Markus Heukelom
In this case, because you call the same function, you could also try a helper function: // GetParameters retrieves multiple parameters using GetParameter. func GetParameters(params ...string) ([]string, error) { var values []string for _, param := range params { value, err := GetParameter(param)

Re: [go-nuts] Question on the generics proposal and arrays

2020-10-07 Thread Markus Heukelom
On Wed, Oct 7, 2020 at 9:12 PM Howard C. Shaw III wrote: > You said: > >> I was trying around with arrays and generics because slices are more >> complex to reason about than arrays. For example, I introduced bugs into my >> code by not being fully aware of slices overwriting original data when y

Fwd: [go-nuts] Question on the generics proposal and arrays

2020-10-07 Thread Markus Heukelom
On Tue, Oct 6, 2020 at 7:45 PM Ian Lance Taylor wrote: > On Tue, Oct 6, 2020 at 6:32 AM Markus Heukelom > wrote: > > > > It appears to me the current proposal does not allow you to write a > function that sorts an array of any size: > > > > func SortArray[T com

[go-nuts] Question on the generics proposal and arrays

2020-10-06 Thread Markus Heukelom
It appears to me the current proposal does not allow you to write a function that sorts an array of any size: func SortArray[T comparable](array [??]T, less func(a, b T) bool) [??]T {} Is it correct that this is not possible? Or is this expressed differently? To clarify, I am seeking for someth

Re: [go-nuts] [generics] Was "no type contracts" considered?

2020-08-12 Thread Markus Heukelom
On Mon, Aug 10, 2020 at 8:30 PM Ian Lance Taylor wrote: > On Mon, Aug 10, 2020 at 6:07 AM Markus Heukelom > wrote: > > > > For what it is worth: for non-exported functions/types all operations > could be allowed, possibly leading to infamous C++-level error messages but &g

Re: [go-nuts] Re: [generics] How to use maps in generic structs?

2020-08-11 Thread Markus Heukelom
On Mon, Aug 10, 2020 at 8:25 PM Ian Lance Taylor wrote: > On Mon, Aug 10, 2020 at 7:08 AM Markus Heukelom > wrote: > > > > Just a quick thought, instead of "comparable" (and type lists) maybe we > could use a single operator to specify the required "operators

Re: [go-nuts] Re: [generics] How to use maps in generic structs?

2020-08-10 Thread Markus Heukelom
Just a quick thought, instead of "comparable" (and type lists) maybe we could use a single operator to specify the required "operators" interface: type BiMap[type V, K ==] struct { forward map[K]V reverse map[V]K } func Max[type T <](a, b T) T { } func ScanRowStruct[type T .](rows sql.Rows, des

Re: [go-nuts] [generics] Was "no type contracts" considered?

2020-08-10 Thread Markus Heukelom
On Sun, Jul 19, 2020 at 3:16 AM Ian Lance Taylor wrote: > On Sat, Jul 18, 2020 at 4:55 AM Markus Heukelom > wrote: > > > > Concerning the current generics proposal, was it every considered to not > allow type contracts at all? > > > > No type contracts would mea

[go-nuts] [generics] How to use maps in generic structs?

2020-08-10 Thread Markus Heukelom
This is invalid: type BiMap[type V, K] struct { forward map[K]V reverse map[V]K } How do I specify an interface constraint for V,K such that this is valid? Is that possible at all? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscr

[go-nuts] Question on gofmt and go vet and field tag keys

2020-07-23 Thread Markus Heukelom
Is there a way to instruct gofmt (or another tool) to reformat field tags such that the keys are aligned? For example: type Example struct { Field1 string `json:"x" db:"y"` Field2 int `json:"ababababc" db:"def"` Field3 string `json:"zyx" db:"egh"` Field4 string `json:"z" db:"q"` } Would be for

Re: [go-nuts] Go 2 review process

2020-07-20 Thread Markus Heukelom
Would it be an idea to allow people only to label something as proposal if they have at least some support / voucher for the idea? Say N>10 general upvotes or 1 upvote from a golang committer? By allowing the "proposal" label, you sort of give people the idea that their idea will be "triaged",

Re: [go-nuts] [generics] Was "no type contracts" considered?

2020-07-19 Thread Markus Heukelom
if care is taken that it could reasonably added later). It's just something that could be considered. -Markus On Sunday, July 19, 2020 at 3:17:07 AM UTC+2 Ian Lance Taylor wrote: > On Sat, Jul 18, 2020 at 4:55 AM Markus Heukelom > wrote: > > > > Concerning the current gener

Re: [go-nuts] [generics] question regarding package level generic type declarations

2020-07-19 Thread Markus Heukelom
Or we don't indent. As long as it is consistent and automatic. I think the grouping is could also especially helpful in the documentation, to get rid of redudant "noisy" type parameter lists. On Sunday, July 19, 2020 at 3:15:12 AM UTC+2 Ian Lance Taylor wrote: > On Sat,

[go-nuts] [generics] Was "no type contracts" considered?

2020-07-18 Thread Markus Heukelom
Concerning the current generics proposal, was it every considered to not allow type contracts at all? No type contracts would mean that generic functions can only use =, & on variables of parametric types, as these are always available for all types. Nothings else is allowed. This would remo

Re: [go-nuts] [generics] question regarding package level generic type declarations

2020-07-18 Thread Markus Heukelom
hings symmetric, a single generic function would have to be specified with something like this generic (type T1, T2) func Map(s []T1, func(T1) T2) []T2. type Vertex generic (type T) struct { Coords [3]T } On Fri, Jul 17, 2020 at 8:26 PM Ian Lance Taylor wrote: > On Fri, Jul 17, 2020 at 1:56 A

[go-nuts] [generics] question regarding package level generic type declarations

2020-07-17 Thread Markus Heukelom
The authors of the current generics proposal mention that they looked into doing generics only on package level:( https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#why-not-put-type-parameters-on-packages ) I understand the reasons what it wasn't pursued f

Re: [go-nuts] [generics] Data structures and the garbage collector

2020-07-10 Thread Markus Heukelom
> Many data structures are implemented using pointers. How does this perform >> wrt garbage collecting? For example take any data structure that uses some >> tree of nodes, or even simpler just a singly linked list: there is one >> pointer from the left node to the next. Wouldn't this incur hu

[go-nuts] [generics] Data structures and the garbage collector

2020-07-09 Thread Markus Heukelom
Hi, Many data structures are implemented using pointers. How does this perform wrt garbage collecting? For example take any data structure that uses some tree of nodes, or even simpler just a singly linked list: there is one pointer from the left node to the next. Wouldn't this incur huge GC (