At the moment, I have the following Scala code using the Scala Graph library:
val g = Graph.from(nodes, edges)
// nodes: List[Table]; edges: List[LkUnDiEdge[Table,String]]
// inferred - g: Graph[Table, LkUnDiEdge]
...
def nodeTransformer(innerNode: Graph[Table, LkUnDiEdge]#NodeT) = {
val node = innerNode.value
Some( root,
DotNodeStmt(node.name, style(node)) )
}
You may notice the parameter to nodeTransformer
is an inner type of the type of g
. Similar code repeats the concrete Graph type or some of its type parameters in other places in the codebase.
Type inference does not work in all places, and I'd like a way to express this type dependency without repeating the same explicit types throughout the code. As an example, the C++ typeof
operator would allow me to rewrite the function as follows:
def nodeTransformer(innerNode: typeof(g)#NodeT) = {
...
}
What is the sane way to express such static type dependencies in Scala when type inference fails?