Custom polymorphic type?

In Go, how do you work with polymorphism?
For example I can create type constraints like this:

type
  Comparable = concept a, b 
    type(a < b) is bool
    type(a  ==  b) is bool

Now I can use Comparable as a polymorphic type:

proc sort(ls: var arr[Comparable]) = 
    # ...

Can you do this on go?

In Go you would probably implement an interface for that. But you should be more specific about what your types should have in common.

Your Comparable example is not easy to translate directly into Go: the closest thing, however is the sort.Interface: https://golang.org/src/sort/sort.go?s=505:783#L4

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.