zlacker

[return to "Go(lang): Robust generic functions on slices"]
1. gslall+Ng3[view] [source] 2024-02-24 09:47:08
>>signa1+(OP)
> func Index[S ~[]E, E comparable](s S, v E) int {

After seeing this signature, I think that Go is giving up on it's simpleness principle.

◧◩
2. quickt+wj3[view] [source] 2024-02-24 10:30:40
>>gslall+Ng3
what does the ~ do here anyway?
◧◩◪
3. onefiv+qk3[view] [source] 2024-02-24 10:44:03
>>quickt+wj3
type Something []string

ensure that the underlying type is a slice

◧◩◪◨
4. shakow+6l3[view] [source] 2024-02-24 10:55:22
>>onefiv+qk3
Why do you need a tilda for `S ~[]E`, but not for `E comparable`?

Both are type-constraining annotations, so why two syntaxes?

◧◩◪◨⬒
5. therei+Tl3[view] [source] 2024-02-24 11:05:36
>>shakow+6l3
It is like S: where S = []E where E: comperable.

I like the way Rust has it a lot more but it is still imperfect and feels arbitrary in ways.

I find myself unsure where to put the templatization parameters and it doesn't feel perfectly symmetrical.

Unsure if impl MyType<T> where T: X

is comperable to impl MyType<T: X> Sometimes it needs impl<T> MyType<T> where T: X

◧◩◪◨⬒⬓
6. shakow+1n3[view] [source] 2024-02-24 11:22:23
>>therei+Tl3
Agreed, the Rust syntax is no golden standard either - but at least it's regular; this one really weirds me out.
[go to top]