Vertex
とEdge
のタイプが相互に依存する単純なグラフ表現を作成したいとします。具体的な実装は次のようになります。
case class Edge(id: Int, label: String, endpoints: (Vertex, Vertex))
case class Vertex(id: Int, data: Data, edges: Map[Int, Edge])
Edge
に依存しVertex
、その逆も同様です。私が本当に欲しいのはid
、data
などにジェネリック型を持たせることです。そして、これを最良の方法で設計する方法を知りたいですか?
trait Vertex[A, B] {
def id: A
def data: B
// What about types for the edges etc?
}
trait Edge[A, ...] {
def id: A
def label: String
def endpoints: (Vertex[...], Vertex[...])
}
この簡単な例をいただければ幸いです。