vmware / differential-datalog

DDlog is a programming language for incremental computation. It is well suited for writing programs that continuously update their output in response to input changes. A DDlog programmer does not write incremental algorithms; instead they specify the desired input-output mapping in a declarative manner.
MIT License
1.38k stars 118 forks source link

Inversion of control and/or traits in DDlog #830

Open AndrewBrownK opened 3 years ago

AndrewBrownK commented 3 years ago

Would it be possible to create and implement traits (or interfaces or typeclasses) in DDlog?

What I would like is inversion of control. I want some framework-like DDlog that can operate on any DDlog types that implement a trait. Then I want app-specific DDlog that can implement this trait. The framework-DDlog is responsible for (perhaps generic) inputs and outputs, but doesn't depend on the app-DDlog to compile. The app-DDlog can use the framework-DDlog to declare inputs and outputs and then customizes app-specific behavior by implementing the trait(s).

From wikipedia:

in traditional programming, the custom code that expresses the purpose of the program calls into reusable libraries to take care of generic tasks, but with inversion of control, it is the framework that calls into the custom, or task-specific, code.

Questions

  1. Would it be possible to create and implement traits (or interfaces or typeclasses) in DDlog?
  2. Do "traits" even make sense to be a thing in a language like DDlog? Apologies if the question is nonsensical
  3. What other patterns might/should I consider to implement something like inversion of control?

It won't be the end of the world if I have to make my framework-like DDlog hard-coupled with my app-like DDlog. I'd just like to poke at and discuss this subject before I get too far committed to an implementation either way.

ryzhyk commented 3 years ago
  1. Unfortunately, not at the moment.

  2. I think they do. Although the exact definition may not be completely obvious. DDlog consists of the imperative fragment (functions and expressions) and declarative fragment (relations and rules). It is relatively straightforward to add generics to the imperative fragment, e.g., by exposing a simplified version of the Rust traits system. But what exactly generics should look like for the declarative fragment is a more interesting question and a nice language design exercise that we haven't done yet.

  3. I don't have a good general answer, but if you have a specific task, e.g., a simplified version of whatever you would like to implement in DDlog, I'll be happy to brainstorm potential solutions together.

mihaibudiu commented 3 years ago

I like Souffle's generic components: https://souffle-lang.github.io/components That would be a way to use generic relations.