What is the comparable interface called?
<p>I'm working on a simple linked list implementation in Go for learning purposes.  The definition of an element is below:</p>
<pre><code>type Element struct {
    next, prev *Element
    Value      interface{}
}
</code></pre>
<p>As you can see, the Value can be anything that satisfies the empty interface.  Now, as a new feature, I would like to make it so that when you insert a new element into the list, it inserts it in a sorted manner - each element will be &lt;= the next.</p>
<p>In order to do this, I wrote the following method:</p>
<pre><code>func (l *LinkedList) Add(val interface{}) *Element {
    this := &amp;l.Root
    e := Element{Value: val}
    for {
        if this.next.Value != nil &amp;&amp; this.next.Value &lt; val {  // &lt;-comparison here
            this = this.next
        } else {
            return l.insert(&amp;e, this)
        }
    }
}
</code></pre>
<p>The compiler complains <code>operator &lt; not defined on interface</code> which is fair.  So I understand that in my Element typedef, I should restrict Value to types that can be compared using the <code>&lt;</code> operator.  I learned this while researching this problem that Go does not support operator overloading - I am not trying to do that.  Instead, I am just trying to make sure that Element.Value is a type that can be compared using the <code>&lt;</code> operator. How do I do this?</p>
<h2>Update:</h2>
<p>It occurs to me that it might not be too difficult to simple define a new type, based on a built-in, that can be compared through some function.  so I wrote this mess (as well as a bunch of other ways of trying to do the same thing):</p>
<pre><code>type Comparable interface {
    LessThan(j interface{}) bool // tried (j Comparable), (j MyInt), etc
    EqualTo(j interface{}) bool  // tried (j Comparable), (j MyInt), etc
}

type MyInt int

func (i MyInt) LessThan(j MyInt) bool {
    return i &lt; j
}

func (i MyInt) EqualTo(j MyInt) bool {
    return i == j
}

type Element struct {
    next, prev *Element
    Value      Comparable
}
</code></pre>
<p>What I would really like is to define an interface, which, if implemented for a type, provides functions <code>LessThan</code> and <code>EqualTo</code> that operate on two instances of that type and provides a bool - something like <code>LessThan(i, j WhatEvers) bool</code> which can be used in place of <code>&lt;</code>.  I realize below it's implemented as an instance method - I've tried both ways but no success.  With the above, I would use it something like: <code>this.next.Value.LessThan(val)</code> in the Add function.  I get either:</p>
<pre><code>linkedlist.MyInt does not implement linkedlist.Comparable (wrong type for EqualTo method)
    have EqualTo(linkedlist.MyInt) bool
    want EqualTo(interface {}) bool
</code></pre>
<p>or</p>
<pre><code>linkedlist.MyInt does not implement linkedlist.Comparable (wrong type for EqualTo method)
    have EqualTo(linkedlist.MyInt) bool
    want EqualTo(linkedlist.Comparable) bool
</code></pre>
<p>Is this possible to use an interface to require that a certain function must exist that operates on two instances of a custom type, or is it only for Methods?</p>