This is an implementation of the Mini Kanren logic system for the CLR. This was done last night, so you can take it with a pinch of salt. It does not cover the full set of constructs that original MK system covers. Here is a overly simplified introduction to miniknaren.
This implementation is done in Cw, the experimental language from MSR. You will need the COmega compiler if you wish to compile the source.
This implementation covers the basic ‘run’, ‘all’ and ‘conde’ constructs. You do not need a ‘fresh’ because I use the Cw type system and scoping to give me the equivalent of fresh. MiniKanren is implemented as an embedded language in scheme – so you get to do relational programming and then drop into scheme’s functional host language as need be. Since this implementation runs over Cw, this extends and hence you get a combination of a declarative logic programming system on top of everything that is Cw.
I am considering adding some more constructs and maybe a relational arithmetic system. I am also considering extending Cw syntax using an external precompiler so that it becomes as little more natural to write relational programs. The present ‘syntactic beauty’ is well a little lacking..
All that said, here are the sources from last night.
q = new Var();
a = new Var();
b = new Var();
c = new Var();
res = Mk.run( q,
Mk.eq( q, new object[]{ a, b}),
Mk.eq( a, c ),
Mk.eq( c, 10),
Mk.conde(
new goal[]{ Mk.eq(b, 5) },
new goal[]{ Mk.eq(b, 10) },
new goal[]{ Mk.eq(b, 20) },
new goal[]{ Mk.eq(b, 25) },
new goal[]{ Mk.eq(a, 50) }
));
//res is the potentially infinite lazy evaluated set
r = res.{ return Var.ToString( it ); };
r.{ Console.WriteLine( it ); };
A logic programming system is a great way to implement solutions to several kinds of problems like dependency analysis, all searching any relational space (ex: A Type Discipline for Authorization Policies)
Disclaimer:
(I am not responsible for your divergences).
(I am also not responsible for any halting problems with your compilation process).
(The full credit of MK goes to its original authors. This implementation is merely a transliteration with a certain imperative flavor added).
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Roshan James
E-mail