travitch / datalog Goto Github PK
View Code? Open in Web Editor NEWA pure Haskell implementation of Datalog
License: BSD 3-Clause "New" or "Revised" License
A pure Haskell implementation of Datalog
License: BSD 3-Clause "New" or "Revised" License
The tests demonstrate how to make a database from scratch and query it. But what if you wanted to add a relationship to an existing database, or assert that a relationship holds for a new tuple?
where
q = do
use <- relationPredicateFromName "use"
def <- relationPredicateFromName "def"
succ <- relationPredicateFromName "succ"
live <- inferencePredicate "live"
live2 <- inferencePredicate "live2"
let l = LogicVar "l"
l' = LogicVar "l'"
t = LogicVar "t"
t' = LogicVar "t'"
(live, [l,t]) |- [ lit use [l,t] ]
(live, [l,t]) |- [ lit live [l',t]
, lit succ [l, l']
, negLit def [l, t] ]
(live2, [l,t]) |- [ lit live [l,t] ]
issueQuery live2 [l,t]
Hi there, I seem to be having some trouble with inference predicates that require other inference predicates. In the above code, if I issue the query for live
instead of live2
everything works fine, and it actually generates liveness. If, however, I query for live2
, the database produces nothing. Any idea as why this might be?
Are you intending to put this on hackage?
I ask because the README says "Rewrite literals like f(X,X) into f(X,Y), X=Y. A few internals assume that the same variable doesn't appear twice in a literal" -- but it says that under "Planned Enhancements", as opposed to (a hypothetical section called) "instructions to the user".
The following code generates a RangeRestrictionViolation in the MagicSets transformation
db2 :: Maybe (Database Text)
db2 = makeDatabase $ do
stateRel <- addRelation "state" 2
let facts :: [[Text]]
facts = [ [ "b", "z" ]
]
mapM_ (assertFact stateRel) facts
tq3 :: IO ()
tq3 = do
let Just db = db2
q = do
stateRel <- relationPredicateFromName "state"
toggle <- inferencePredicate "toggle"
let x = LogicVar "x"
y = LogicVar "y"
(toggle, [Atom "a", y]) |- [ lit stateRel [Atom "b", y] ]
(toggle, [Atom "b", y]) |- [ lit stateRel [Atom "a", y] ]
issueQuery toggle [x, y ]
res <- queryDatabase db q
putStrLn ("res=" ++ (show res))
FYI, I am trying to capture the following rules
toggle(1, T) :- state(0, T). toggle(0, T) :- state(1, T).
looks pretty great / seems buildable, whats blocking a release atm?
You might consider basing a future REPL on the one in https://github.com/pchiusano/datalog-refactoring which is quite modular.
How do you query with the REPL?
chris@retina:~/Projects/datalog$ datalog-repl
% human(chris).
% :facts
human(chris).
% ?human(X).
Query result:
datalog-repl: No rules for pattern
@pchiusano does your version support this?
I built it with Stack instead of Cabal. Stack seems to think it needs a really old resolver:
jeff@jbb-lenovo:~/code/datalog$ stack init
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- datalog.cabal
Selecting the best among 11 snapshots...
* Partially matches lts-9.9
transformers version 0.5.2.0 found
- datalog requires >=0.3 && <0.5
vector version 0.12.0.1 found
- datalog requires >=0.9 && <0.11
* Partially matches nightly-2017-10-21
transformers version 0.5.2.0 found
- datalog requires >=0.3 && <0.5
vector version 0.12.0.1 found
- datalog requires >=0.9 && <0.11
* Partially matches lts-8.24
transformers version 0.5.2.0 found
- datalog requires >=0.3 && <0.5
vector version 0.11.0.0 found
- datalog requires >=0.9 && <0.11
* Partially matches lts-7.24
transformers version 0.5.2.0 found
- datalog requires >=0.3 && <0.5
vector version 0.11.0.0 found
- datalog requires >=0.9 && <0.11
* Partially matches lts-6.35
vector version 0.11.0.0 found
- datalog requires >=0.9 && <0.11
* Partially matches lts-5.18
vector version 0.11.0.0 found
- datalog requires >=0.9 && <0.11
* Partially matches lts-4.2
vector version 0.11.0.0 found
- datalog requires >=0.9 && <0.11
* Matches lts-3.22
Selected resolver: lts-3.22
Initialising configuration using resolver: lts-3.22
Total number of user packages considered: 1
Writing configuration to file: stack.yaml
All done.
jeff@jbb-lenovo:~/code/datalog$
I would like to use it in a project with more recent dependencies. Is there a way?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.