Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ekzhang/ukanren-rs
Rust implementation of µKanren, a featherweight relational programming language.
https://github.com/ekzhang/ukanren-rs
functional-programming language logic-programming microkanren minikanren prolog rust
Last synced: 5 days ago
JSON representation
Rust implementation of µKanren, a featherweight relational programming language.
- Host: GitHub
- URL: https://github.com/ekzhang/ukanren-rs
- Owner: ekzhang
- License: mit
- Created: 2021-09-10T03:28:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-01T20:59:49.000Z (about 2 years ago)
- Last Synced: 2024-05-22T22:32:27.335Z (8 months ago)
- Topics: functional-programming, language, logic-programming, microkanren, minikanren, prolog, rust
- Language: Rust
- Homepage: https://docs.rs/ukanren
- Size: 38.1 KB
- Stars: 107
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-formalized-reasoning - µKanren-rs - implementation of µKanren. (Kanren / Libraries)
README
# µKanren-rs
[](https://github.com/ekzhang/ukanren-rs)
[](https://crates.io/crates/ukanren)
[](https://docs.rs/ukanren)
[](https://github.com/ekzhang/ukanren-rs/actions?query=branch%3Amain)This is a Rust implementation of µKanren, a featherweight relational programming
language. See the original Scheme implementation
[here](http://webyrd.net/scheme-2013/papers/HemannMuKanren2013.pdf) for
reference.## Features
- Structural unification of Scheme-like cons cells.
- Streams implemented with the `Iterator` trait.
- State representation using a persistent vector with triangular substitutions.
- Conjunction, disjunction, and `fresh` based on traits (macro-free API).
- Lazy goal evaluation using inverse-η delay.
- Integer, `bool`, `char`, `&str`, and unit type atoms.
- Explicit `ToValue` trait that converts vectors and arrays into cons-lists.
- Convenience macro `state!` to inspect and specify state.## Usage
Here's a simple example, which defines and uses the `appendo` predicate.
```rust
use ukanren::*;fn appendo(first: Value, second: Value, out: Value) -> BoxedGoal> {
eq(&first, &())
.and(eq(&second, &out))
.or(fresh(move |a: Value, d: Value, res: Value| {
eq(&(a.clone(), d.clone()), &first)
.and(eq(&(a, res.clone()), &out))
.and(appendo(d, second.clone(), res))
}))
.boxed()
}let iter = run(|x, y| appendo(x, y, [1, 2, 3, 4, 5].to_value()));
assert_eq!(
iter.collect::>(),
vec![
state![(), [1, 2, 3, 4, 5]],
state![[1], [2, 3, 4, 5]],
state![[1, 2], [3, 4, 5]],
state![[1, 2, 3], [4, 5]],
state![[1, 2, 3, 4], [5]],
state![[1, 2, 3, 4, 5], ()],
],
);
```More examples can be found in the `tests/` folder and the API documentation.
Made by Eric Zhang for
CS 252r. All code is
licensed under the MIT License.