bio4j / dynamograph

GSoC 2014 project - a DynamoDB based graph DB
GNU Affero General Public License v3.0
4 stars 1 forks source link

Scarph #9

Closed alberskib closed 10 years ago

alberskib commented 10 years ago

@bio4j/dynamograph I have some questions regarding scarph. Answers for those questions enables me understanding it, so please be patient in case of any stupid questions.

/* Get source/target from this representation */
  abstract class GetSource[S <: AnyVertex.ofType[Tpe#SourceType]](val source: S) {
    def apply(edgeRep: edge.Rep): source.Rep
  }
  abstract class GetTarget[T <: AnyVertex.ofType[Tpe#TargetType]](val target: T) {
    def apply(edgeRep: edge.Rep): target.Rep
  }

and they are used later as an implicits. Is there any special reason why their are created instead of functions? I mean why to use functional objects instead of functions.

alberskib commented 10 years ago

There is one more thing:

laughedelic commented 10 years ago

I'll try to answer, but I may be wrong on imprecise in something (so maybe @eparejatobes will add something). And don't worry if you don't understand some code — it's really non-trivial, so it's normal to ask questions.

About your first question: as you see in the following part of code (in the same file that you refer), we add such methods to edge.Rep:

def source[S <: Singleton with AnyVertex.ofType[Tpe#SourceType]](implicit getter: GetSource[S]) = getter(edgeRep)

so we want those GetSource things to be implicit objects. The point is that it gives us flexibility, because these part of implementation are detached from each other:

and it can be defined there, or in any other place. The only requirement is that it should be in scope when you want to use it.

Same applies to retrieving properties and ingoing/outgoing edges for a vertex. For an example of external creation of a target getter see this test.

P.S. I've just published it (0.1.0-SNAPSHOT)

alberskib commented 10 years ago

so we want those GetSource things to be implicit objects

As far as I know you can also create an implicit function which will work similarly

implicit def sourceType2sourceRep( ...
laughedelic commented 10 years ago

Could you extend this piece of code? So far I don't see what you mean.

laughedelic commented 10 years ago

About denotation thing.

I mean why it is important

Well, it's just a generalization which appeared while we were refactoring the code.

First, as it's said in the comments:

This trait represents a mapping between

  • members Tpe of a universe of types TYPE
  • and Raw a type meant to be a denotation of Tpe thus the name

    Tagging is used for being able to operate on Raw values knowing what they are denotating.

(by the way, the actual comment mixes Rep and Raw (Rep is just a tagged Raw)).

So for example:

So with all these layers you can see, that with vertex types we can define the graph schema abstractly (godSchema), and then "implement" it (godsImplementation), defining vertices which denote those vertex types with a particular implementation (Raw = TitanVertex).

The reason why we want to have this "double" types structure, is that we want to deal with a universe of types (i.e. a defined limited set of them), and operate on them as on values, which would be impossible otherwise.

P.S. I hope I understood your questions right. If not, ask again. And I hope @eparejatobes will say something too ")

eparejatobes commented 10 years ago

I have intermittent access to internet, anyway I'll try to answer briefly

alberskib commented 10 years ago

So with all these layers you can see, that with vertex types we can define the graph schema abstractly (godSchema), and then "implement" it (godsImplementation), defining vertices which denote those vertex types with a particular implementation (Raw = TitanVertex).

The reason why we want to have this "double" types structure, is that we want to deal with a universe of types (i.e. a defined limited set of them), and operate on them as on values, which would be impossible otherwise.

Thanks a lot. I think that more or less I understand it - now it is easier for me to use it (but still it is good idea to discuss about it).

laughedelic commented 10 years ago

I'm glad that it helps. In general, I recommend you to start from examples in tests to see how things are used and from there look up how those things are defined.

eparejatobes commented 10 years ago

@bio4j/dynamograph i could prepare a walkthrough for the library, explaining what were my ideas/motivations for it. Tomorrow or the day after? I have a lot of meetings and stuff these days but early morning (7:00AM) US EST is fine for me. Moving this to Gitter chat

laughedelic commented 10 years ago

ok. fine for me

alberskib commented 10 years ago

Unfortunately I cannot take part at suggested time tommorow or day after (11AM - 5PM US EST is ok). Alternatively wednesday at 7:00 AM US EST is ok for me.

eparejatobes commented 10 years ago

@bio4j/dynamograph closing?