Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How does Datalog differ from something like MiniKanren?


My take on miniKanren is that it's implementation is designed to be small and hackable. Especially small with microKanren. If you don't know scheme/lisp, but want to roll your own for educational purposes, then check this out: https://codon.com/hello-declarative-world

Vs Prolog, the emphasis in miniKanren is on constraint programming --- especially writing new constraints to extend it to more problems. Where (chief variants of) Prolog have been optimized in various ways for certain types of problems.

See Will Byrd's answer here: https://stackoverflow.com/questions/28467011/what-are-the-ma...

What I read about Datalog is that it is basically a recursive relational database. It's set up for "deductive queries". This wording reminds me of miniKanren --- but the Kanrens are Turing complete.

Ah, Wikipedia has this to say:

In contrast to Prolog, Datalog,

1.) disallows complex terms as arguments of predicates, e.g., p (1, 2) is admissible but not p (f (1), 2),

2.) imposes certain stratification restrictions on the use of negation and recursion,

3.) requires that every variable that appears in the head of a clause also appears in a nonarithmetic positive (i.e. not negated) literal in the body of the clause,

4.) requires that every variable appearing in a negative literal in the body of a clause also appears in some positive literal in the body of the clause[4]

I'd have to put some thought into checking this list against the capabilities of miniKanren. Generally it doesn't ring any bells.


miniKanren is Turing-complete; Datalog deliberately isn't.

Despite that, there are things Datalog can do easily that miniKanren can't. miniKanren can't handle negation natively, but Datalog can (as long as it's stratified, that is, a predicate can't use its own negation).

Datalog is also forward-chaining, so some things that would infinite loop in miniKanren work fine in Datalog - for example, computing the transitive closure of a cyclic graph. If someone added tabling to miniKanren that would solve this.

There's also the question of performance. Some miniKanren implementations are surprisingly fast for what it does, but I suspect they can't compete with, say, Souffle, for the kind of static analysis workloads it's aimed at. Would love to be proven wrong, though.


A Datalog program is guaranteed to terminate (if finite databases). A prolog or miniKanren one doesn’t. Datalog is not Turing-complete.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: