Trait ukanren::Goal [−][src]
pub trait Goal {
type Iter: Iterator<Item = State>;
fn apply(&self, s: &State) -> Self::Iter;
fn and<G, I>(self, other: G) -> And<Self, G>
where
Self: Sized,
G: Goal<Iter = I>,
I: Iterator<Item = State>,
{ ... }
fn or<G, I>(self, other: G) -> Or<Self, G>
where
Self: Sized,
G: Goal<Iter = I>,
I: Iterator<Item = State>,
{ ... }
fn boxed(self) -> BoxedGoal<Self::Iter>
where
Self: Sized + 'static,
{ ... }
fn run(&self, k: usize) -> RunStream<Self::Iter> { ... }
}
Expand description
A goal that can be executed by the relational system.
Associated Types
Required methods
Provided methods
Take the conjunction of this goal with another.
Example
use ukanren::{eq, fresh, Goal};
// Goal where `x` is equal to `5` and `y` is equal to `6`.
fresh(|x, y| eq(&x, &5).and(eq(&y, &6)));
Take the disjunction of this goal with another.
Example
use ukanren::{eq, fresh, Goal};
// Goal where `x` is equal to `5` or `x` is equal to `6`.
fresh(|x| eq(&x, &5).or(eq(&x, &6)));
Box this goal into a trait object, making it easier to name the type.
Example
use ukanren::{eq, BoxedGoal, Goal, Value, State};
fn animalo(x: Value) -> BoxedGoal<impl Iterator<Item = State>> {
eq(&x, &"dog").or(eq(&x, &"cat")).boxed()
}
Evaluate this goal on an empty state, returning a stream of results.
These results contain normalized forms of the first k
variables, to
avoid including auxiliary data that is not relevant to us.
This is a low-level function. Instead of calling this function directly,
you should probably use the top-level run
function instead, which
infers the value of k
from your input.