This has nothing to do with generics. It is a FAQ regarding the conversion
of a container type value. You cannot modify the type of the object in a
container in a called context. This has been true before generics was
introduced. Ignoring generics what do you think should happen if you call a
function that requires a `[]any` slice and pass it a `[]float64` slice?
Consider this pre-generic example:
package main
func do([]any) {
}
func main() {
var a []float64
do(a)
}
On Tue, Oct 10, 2023 at 12:01 AM Torsten Bronger <
[email protected]> wrote:
> Hallöchen!
>
> The two most recent Go blog articles make we wonder why
>
> package main
>
> func do[T []E, E any](slice T) {
> }
>
> func main() {
> var a []float64
> do(a)
> }
>
> is valid while
>
> package main
>
> func do[T []any](slice T) {
> }
>
> func main() {
> var a []float64
> do(a)
> }
>
> is not. The error message doe not help me. Can someone explain
> this? Thank you!
>
> Regards,
> Torsten.
>
> --
> Torsten Bronger
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/87bkd7nern.fsf%40physik.rwth-aachen.de
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_zQ_5wHg3teOrJPCyvLzN2mAE%2BN8cX3u_4iUCY%2Bev8wg%40mail.gmail.com.