prepublish

This commit is contained in:
mehbark 2024-12-08 21:31:53 -05:00
parent 3c80563ed6
commit c963330384

View file

@ -15,7 +15,7 @@ use thiserror::Error;
/// A representation of a term of the /// A representation of a term of the
/// [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus), using /// [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus), using
/// [de Bruijn indices](https://en.wikipedia.org/wiki/De_Bruijn_index). /// [de Bruijn indices](https://en.wikipedia.org/wiki/De_Bruijn_index).
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum LC { pub enum LC {
/// A lambda abstraction; binds a new variable. /// A lambda abstraction; binds a new variable.
Abs(Rc<LC>), Abs(Rc<LC>),
@ -111,7 +111,7 @@ impl fmt::Display for LC {
/// A representation of a term of the /// A representation of a term of the
/// [SKI combinator calculus](https://en.wikipedia.org/wiki/SKI_combinator_calculus). /// [SKI combinator calculus](https://en.wikipedia.org/wiki/SKI_combinator_calculus).
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum SKI { pub enum SKI {
/// The S (substitution) combinator. /// The S (substitution) combinator.
/// ///
@ -162,12 +162,6 @@ impl fmt::Display for SKI {
} }
} }
#[derive(Debug, PartialEq, Eq)]
pub enum Iota {
Iota,
App(Rc<Iota>, Rc<Iota>),
}
#[derive(Debug, Error, PartialEq, Eq)] #[derive(Debug, Error, PartialEq, Eq)]
pub enum SKICompileError { pub enum SKICompileError {
#[error("LC term has a free variable")] #[error("LC term has a free variable")]
@ -179,9 +173,41 @@ impl TryFrom<LC> for SKI {
type Error = SKICompileError; type Error = SKICompileError;
fn try_from(term: LC) -> Result<Self, Self::Error> { fn try_from(term: LC) -> Result<Self, Self::Error> {
if term.has_free() { use SKI::{App, I, K, S};
return Err(SKICompileError::FreeVar); Ok(match term {
} LC::Abs(x) => match &*x {
todo!() LC::Abs(y) => match &**y {
// x
LC::Var(1) => K,
LC::Abs(z) => match z {
LC::App(_, _) => todo!(),
_ => todo!(),
},
_ => todo!(),
},
LC::Var(0) => I,
_ => todo!(),
},
LC::App(f, x) => {
let f: SKI = f.try_into()?;
let x: SKI = x.try_into()?;
f.app(x)
}
LC::Var(_) => Err(SKICompileError::FreeVar)?,
})
} }
} }
impl TryFrom<Rc<LC>> for SKI {
type Error = SKICompileError;
fn try_from(value: Rc<LC>) -> Result<Self, Self::Error> {
(*value).clone().try_into()
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum Iota {
Iota,
App(Rc<Iota>, Rc<Iota>),
}