logpy/logpy — pull request #19 by mrocklin (2013-03-28 16:33:04+00:00)
Title: Dict and Object Unification

This pull request introduces dict unification to LogPy (only on values).

To do this I had to introduce a type dispatch system to unify and reify.

Once you have this it's fairly simple to extend it to other types.

Once you have dict unification it's fairly simple to unify on arbitrary Python objects.

So now LogPy works well on Python objects, not just tuple-trees / s-expressions.

```Python
In [1]: class Foo(object):
def __init__(self, a, b):
self.a = a
self.b = b
...:

In [2]: from logpy import *

In [3]: from logpy.unify import *

In [4]: unify_dispatch[(Foo, Foo)] = unify_object

In [5]: reify_dispatch[Foo] = reify_object

In [6]: x = var('x')

In [7]: run(0, x, (eq, Foo(1, 2), Foo(1, x)))
Out[7]: (2,)

In [8]: (obj,) = run(0, Foo(x, x), (eq, Foo(1, 2), Foo(1, x)))

In [9]: obj.a
Out[9]: 2

In [10]: obj.b
Out[10]: 2
```