Friday, October 07, 2005

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).

Monday, October 10, 2005 1:03:33 PM (Eastern Standard Time, UTC-05:00)
The use of xml to to create an object instance is scary.

Most of the stuff in here flew over my head :-P. Still mighty interesting.



Monday, October 10, 2005 9:49:53 PM (Eastern Standard Time, UTC-05:00)
Oh yes! It has support for tabular and tree structured data on top of supporting object style data supported. The tree structured data is created by choice and tuple types - hence XML style syntax is natural for creating such data instances. If you look carefully, its strongly typed XML-like syntax for expressing tree structured paper.

The important paper in this regard is the one from Microsoft Research -
Programming with Circles, Triangles and Rectangles
by Erik Meijer, Wolfram Schulte and Gavin Bierman
http://research.microsoft.com/~emeijer/Papers/XML2003/xml2003.html


Roshan
Tuesday, October 11, 2005 12:09:37 AM (Eastern Standard Time, UTC-05:00)
I got the reasons for using the xml syntax. Its just that I find it a little wierd.
Sidharth
Thursday, January 12, 2006 9:00:13 PM (Eastern Standard Time, UTC-05:00)
I have a ruby implementation at http://www.thinkingms.com/dolly/homepage/work/Other/Minikanren/Minikanren.zip
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview