1

It seems possible, but I'm not being able to. People make many questions about that usage on class constructor, but I'm unable to use it even on a simple function.

I have a class called DependecyChecker, which is using scalax Graph library. Inside my class, I create a graph and store it in a value, called DAG. Then, there is a method which returns a specific node of the graph. On this method, I specified the return type as this.DAG.NodeT, and it works well.

What I'm trying to do, then, is to pass the return of such a method to another function, outside the class. I'm a bit confused. What I've tried:

def func(arg: DependencyChecker#Graph#NodeT){
  arg
}

def func(arg: DependencyChecker#DAG#NodeT){
  arg
}

def fund[A](arg: A#Graph#NodeT){
  arg
}

def fund[A <: DependencyChecker](arg: A#Graph#NodeT){
  arg
}

None of the above works. I'm kinda running out of ideas, and this seems very simple, yet I cannot find how to do it, nor learn it by myself. How do I do that?

PS. The type Graph is the type of the DAG value, but that type is not store inside my class. It is imported.

Lucas Lima
  • 832
  • 11
  • 23
  • 3
    The syntax with hashes are projections, a type for some enclosing type. You have to carry around the path to the dependent type for it to be meaningful, to distinguish `x.T` from `y.T`. https://stackoverflow.com/questions/12935731/any-reason-why-scala-does-not-explicitly-support-dependent-types/12937819#12937819 – som-snytt Mar 24 '20 at 19:22
  • So, a solution would be actually pass the instance of DependencyChecker I'm working with? – Lucas Lima Mar 24 '20 at 19:38
  • Is `Graph` a type member in `DependencyChecker`? I.e do you have `type Graph` declared inside it? – Alexey Romanov Mar 25 '20 at 07:50
  • No. Graph is the type of `DAG`, which is a value inside DependencyChecker, – Lucas Lima Mar 25 '20 at 13:03

0 Answers0