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
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
>
> @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,
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
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
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
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
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
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
>> 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 -
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
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
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
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)
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
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
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
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
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
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
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
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
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
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",
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
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,
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
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
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
> 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
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
(
31 matches
Mail list logo