On Fri, Nov 20, 2020 at 2:58 PM Reindert Vetter <reind...@outlook.com> wrote:
>
> First of all, thank you for everything you do with Go!
>
> I've had an idea for generic for Go for some time. If it makes no sense, 
> please ignore my email.
>
> The idea is to join the different types through a pipe. This means you do not 
> have to introduce a 'type' in the interface. It is also much easier to 
> convert ordinary types to a generic type.
>
> Some examples:
>
> type typeFloat float64
> type typeInt int
> type stringAble typeFloat|typeInt
>
> func ConvertToString(input stringAble) string {
>    //
> }
>
>
> type stringAble float64|int
>
> func ConvertToString[type T stringAble](input []T) string {
>    //
> }
>
>
> With interfaces:
>
> type stringAble typeFloat|typeInt|error|stringer
>
> func ConvertToString(input stringAble) string {
> //
> }
>
>
> They may not be generics, but you could also allow the following:
>
>
> func ConvertToString(input float64|int) string {
>    //
> }
>
>
> type typeFloat float64
> type typeInt int
>
> func ConvertToString(input typeFloat|typeInt) string {
>    //
> }


This has some similarities to sum types: https://golang.org/issue/19412.

I'm not sure how to write a genreric Min function with this approach.

Thanks for the note.

Ian

-- 
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/CAOyqgcUt8mTmXYO3YYPhSsDuNOjDA%2BzKxfrXKxhFt5vaeQV3BA%40mail.gmail.com.

Reply via email to