[−][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 |
ltup | Create a tuple of logical values with automatic |
val |
Structs
Goal | A container of one of many possible types of goals. |
LVar | A logical variable that represents a potential value of type |
ResolvedState | Derived from an open |
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 |
Fork | Fork a |
IntoVal | Helper for converting into |
IterResolved | Iterate over |
Query | |
ReifyIn | Extract a fully resolved |
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
|
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 |