On Wed, Oct 11, 2023 at 10:31 PM Torsten Bronger <
bron...@physik.rwth-aachen.de> wrote:

> 'Axel Wagner' via golang-nuts writes:
>
> > [...]
> >
> > What would this do?
> >
> > func F(s []any) {
> >     s[0] = "Foo"
> > }
> > func main() {
> >     s := []int{1,2,3,4}
> >     F(s)
> >     fmt.Println(s)
> > }
>
> I think most intuitive would be if this behaved as an implicit
> instantiation of the function with the type passed to it.
>

No. That is a recipe for disaster. You are arguing that container types
(such as slices or maps) should be automatically converted. Such as is done
by the C language for primary types (e.g., char, int, etc.). But even C
does not allow implicitly converting one array type to another. You have a
misunderstanding of what `any` means. The `any` keyword is a shorthand for
`interface{}`. Any concrete type such as `int` is not equivalent to
`interface{}`. Which means that a slice of a non `any` type cannot be
magically converted to a slice of `interface{}`.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD8Pna8xV-4Jm%2BnrhNpKJGWekqxcR5GgO1RtCetnG8A3gQ%40mail.gmail.com.

Reply via email to