tgecho / canrun_rs

A Rust logic programming library inspired by the *Kanren family of language DSLs.
https://docs.rs/canrun/
Apache License 2.0
51 stars 4 forks source link

Feature request: missing trait implementations #33

Open ibb-dinosaur opened 1 month ago

ibb-dinosaur commented 1 month ago

Hello, I am trying to use this implementation of miniKanren in Rust (which I think is the best one and very well documented) and I just noticed that some types don't implement certain traits. I have very little logic programming (and *Kanren) skills, so I'm not sure if there's a reason why these traits are not implemented, but they make working with the types a little harder.

Unify for Value<T> Eq for LVar<T> without the T: Eq constraint Clone for LVec PartialEq, Eq for LVec Ord, PartialOrd for LVar (also I think it would be helpful to add two functions like fn into_raw() -> usize and unsafe fn from_raw(n: usize), but I understand why it doesn't exist)

tgecho commented 3 weeks ago

My default answer would be that missing implementations are probably due to just not having stumbled across a need. I haven't attempted to apply this library to many real world problems, as it kind of exploded beyond my initial use case into a beast of its own. So the ergonomics are definitely uneven at best.

I haven't thought too deeply about your examples (or about canrun generally in a while), but most of them seem reasonable. I am not sure about the last two.

Ord, PartialOrd for LVar: what would the use case be for ordering these? I think the only option would be to use the internal .id, but that feels like an undesirable leak of an implementation detail. This goes even more obviously for the into/from_raw functions.

That said, if you have a use case I don't think I mind adding them too much (probably both as unsafe). This is mostly an experimental library after all!

Also feel free to throw me a PR for any of this if you're still around/interested. It might be a bit before I have time to do it myself.