You can if you define your type as follow: ``` type Symbol = byte ```
On Saturday, December 20, 2025 at 9:23:30 AM UTC+7 [email protected] wrote: > Hi fellow Gophers > > I'd like to propose that we allow type casting between `[]T` and > `[]U`, when the underlying types `T` and `U` are identical. > > For example: > > ``` > type Symbol byte > > func Index(a, b []Symbol) int { > return bytes.Index(a, b) > } > ``` > > Currently, the above code does not compile with the error: > > `cannot use a (variable of type []Symbol) as []byte value in argument to > bytes.Index` > > This proposal suggests to make this allowed since `Symbol` is exactly > identical to `byte`. > > I am aware this has been proposed before, but was turned down since real > world needs at that time were minimal. > However, I now have a real need > <https://github.com/fumin/nag/blob/master/nag.go#L774> in my code for > this feature. > Alternatively, if this kind of slice type conversion is truly disallowed, > can anyone suggest a better way of writing the above function that > maintains its readability and performance? > > Thanks > -- 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 visit https://groups.google.com/d/msgid/golang-nuts/50081cc9-48b8-4e1d-83d4-00f51fa2455bn%40googlegroups.com.
