use crate::domains::{Domain, DomainType};
use crate::goals::{Goal, GoalEnum};
use crate::state::State;
use crate::value::IntoVal;
use crate::UnifyIn;
use std::fmt::Debug;
pub(super) fn run<'a, D>(state: State<'a, D>, a: D::Value, b: D::Value) -> Option<State<'a, D>>
where
D: Domain<'a>,
{
D::unify_domain_values(state, a, b)
}
pub fn unify<'a, T, A, B, D>(a: A, b: B) -> Goal<'a, D>
where
T: UnifyIn<'a, D> + Debug,
A: IntoVal<T>,
B: IntoVal<T>,
D: DomainType<'a, T>,
{
Goal(GoalEnum::UnifyIn(
D::into_domain_val(a.into_val()),
D::into_domain_val(b.into_val()),
))
}
#[cfg(test)]
mod tests {
use crate::example::I32;
use crate::{unify, util, var, Goal};
#[test]
fn deeply_nested_vars() {
let (w, x, y, z) = (var(), var(), var(), var());
let goals: Vec<Goal<I32>> = vec![unify(w, 1), unify(w, x), unify(x, y), unify(y, z)];
util::assert_permutations_resolve_to(goals, z, vec![1])
}
}