[][src]Crate canrun

Canrun is a logic programming library inspired by the *Kanren family of language DSLs.

Status: Exploratory and Highly Experimental

I'm still quite new to both Rust and logic programming, so there are likely to be rough edges. At best the goal is to be a useful implementation of the core concepts of a Kanren in way that is idiomatic to Rust. At worst it may just be a poor misinterpretation with fatal flaws.

Quick Start

use canrun::{Goal, both, unify, var};
use canrun::domains::example::I32;

let x = var();
let y = var();
let goal: Goal<I32> = both(unify(x, y), unify(1, x));
let result: Vec<_> = goal.query(y).collect();
assert_eq!(result, vec![1])

Modules

domains

Constrain the set of types that you can reason about in a particular context.

goal

Make declarative assertions about the relationships between values.

state

Track value bindings and constraints during the evaluation process.

util

Assorted helpers, especially for testing.

value

Contain individual resolved values or variables that can be bound through unification.

Macros

all

Create a goal that only succeeds if all sub-goals succeed.

any

Create a goal that yields a state for every successful sub-goal.

domain

Generate Domain structs and other associated types and impls.

ltup

Create a tuple of logical values with automatic IntoVal wrapping.

val

Easy conversion of LVar<T> and T values into Val<T>.

Structs

Goal

A container of one of many possible types of goals.

LVar

A logical variable that represents a potential value of type T.

ResolvedState

Derived from an open State, depending on the constraints that have been applied.

State

The core struct used to contain and manage value bindings.

Enums

Val

The possible states a value can be in.

Traits

Domain

Manage values for a set of specific types.

DomainType

Allows a State to retrieve values of a specific type from a domain.

Fork

Fork a State into zero or more alternate states.

IntoVal

Helper for converting into Val<T>.

IterResolved

Iterate over ResolvedStates.

Query

Derive reified values potential resolved states.

ReifyIn

Extract a fully resolved T from a Val<T>.

UnifyIn

How compatible values are matched with each other.

Functions

assert_1

Create a projection goal that succeeds if the resolved value passes an assertion test.

assert_2

Create a projection goal that succeeds if the resolved values pass an assertion test.

both

Create a goal that only succeeds if both sub-goals succeed.

custom

Create a goal that gives access to the underlying State struct.

either

Create a goal that succeeds if either sub-goal succeed.

lazy

Create a goal that is generated via callback just as it is about to be evaluated.

map_1

Create a projection goal that allows deriving one resolved value from the other.

map_2

Create a projection goal that allows deriving one resolved value from the other two.

project_1

Create a projection goal that allows creating a new goal based on the resolved value.

project_2

Create a projection goal that allows creating a new goal based on the resolved values.

unify

Create a goal that attempts to unify two values with each other.

var

Create a new logical var.

Type Definitions

StateIter

Type alias for an Iterator of States