Been thinking a bit about "custom unification", or...
# of-logic-programming
e
Been thinking a bit about "custom unification", or extensible unification. It seems it is a pretty common thing: • A library that implements unification / custom unification in JavaScriptExtending unification in clojure's core.logicAn unification library for PythonAlso TIL SWI prolog supports maps/dictionaries Wondering how much it makes sense to use more complex data structures in prolog-like searches. Datalog seems to be an example that going "the other way", being more restrictive, may be more productive:
Datalog disallows complex terms as arguments of predicates, e.g., p (1, 2) is admissible but not p (f (1), 2)
Perhaps unification of complex/custom data structures is more productive for pattern matching than for general logic programming ... but not sure (SWI prolog's dict maybe contradicts this idea).
Also trying to figure out why SWI's dicts include tags. My guess is that they needed the tag anyway so instead of giving it a fixed "functor", say
dict
, they allowed an arbitrary tag name to be used Edit: the manual say dicts are "structs with named arguments", so they need a tag like any other structure, I guess
🤷‍♂️ 1
n
FWIW I came to be interested in Datalog precisely because it didn't have nested data structures. Nested data structures of arbitrary depth must be constructed and deconstructed using ordinary functional-style recursive algorithms, which goes against the whole philosophy of Datalog (in my opinion): performing recursive relational queries (select, join, union, etc.) on flat datasets.
But I've since decided that Datalog isn't expressive enough. Its problem isn't the non-existence of hierarchical data though, it's the inability formally reason about program properties such as termination. (That is, unless you impose severe and/or complicated restrictions on which programs are considered "safe".)
The root of the problem is that rules in Prolog/Datalog don't compose. You can have two rulesets which terminate when run independently, but act non-deterministically (or fail to terminate) when combined.