Function canrun::unify

source ·
pub fn unify<T, A, B>(a: A, b: B) -> Unify<T>where
    T: Unify,
    A: Into<Value<T>>,
    B: Into<Value<T>>,
Expand description

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

If one of the values is an unbound LVar, it will be bound to the other value. If both values are able to be resolved, they will be compared with Unify::unify. If this unification fails, the goal will fail.

Examples

Unifying a fresh LVar will bind it to the other value:

use canrun::{unify, LVar, Query};

let x = LVar::new();
let goal = unify(1, x);
let result: Vec<_> = goal.query(x).collect();
assert_eq!(result, vec![1])

Attempting to unify two unequal values will fail:

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