The compilation error you get basically says that context boundaries cannot be used for type aliases. Context boundaries work in function or class definitions. For instance,
class BST[T: Ordering](val tree: Tree[T])
is an abbreviation for
class BST[T](val tree: Tree[T])(implicit ordering: Ordering[T])
Note that different BST objects can potentially have different Ordering s, and these values ββshould be stored at runtime.
For your use case, itβs easiest to associate the context with the main functions that you mean,
def f[T: Ordering](t1: Tree[T], t2: Tree[T]) { import scala.math.Ordering.Implicits._ t1.get.entry < t2.get.entry }
Then the corresponding Ordering[T] implicit will be found on the call site f , where type T is known.
source share