prepublish
This commit is contained in:
parent
3c80563ed6
commit
c963330384
1 changed files with 38 additions and 12 deletions
48
src/lib.rs
48
src/lib.rs
|
@ -15,7 +15,7 @@ use thiserror::Error;
|
|||
/// A representation of a term of the
|
||||
/// [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus), using
|
||||
/// [de Bruijn indices](https://en.wikipedia.org/wiki/De_Bruijn_index).
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum LC {
|
||||
/// A lambda abstraction; binds a new variable.
|
||||
Abs(Rc<LC>),
|
||||
|
@ -111,7 +111,7 @@ impl fmt::Display for LC {
|
|||
|
||||
/// A representation of a term of the
|
||||
/// [SKI combinator calculus](https://en.wikipedia.org/wiki/SKI_combinator_calculus).
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum SKI {
|
||||
/// 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)]
|
||||
pub enum SKICompileError {
|
||||
#[error("LC term has a free variable")]
|
||||
|
@ -179,9 +173,41 @@ impl TryFrom<LC> for SKI {
|
|||
type Error = SKICompileError;
|
||||
|
||||
fn try_from(term: LC) -> Result<Self, Self::Error> {
|
||||
if term.has_free() {
|
||||
return Err(SKICompileError::FreeVar);
|
||||
use SKI::{App, I, K, S};
|
||||
Ok(match term {
|
||||
LC::Abs(x) => match &*x {
|
||||
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)
|
||||
}
|
||||
todo!()
|
||||
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>),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue