use crate::typing::{Pattern, Term};
#[derive(ocaml::ToValue, ocaml::FromValue)]
pub enum OTerm {
Var(String),
Con(String, Vec<OTerm>),
Leaf(String),
}
impl OTerm {
#[must_use]
pub fn lower(self) -> Term {
match self {
OTerm::Var(n) => Term::Var(n),
OTerm::Con(f, ks) => Term::Con(f, ks.into_iter().map(OTerm::lower).collect()),
OTerm::Leaf(s) => Term::Leaf(Pattern::raw(&s)),
}
}
#[must_use]
pub fn lift(t: &Term) -> Self {
match t {
Term::Var(n) => OTerm::Var(n.split('#').next().unwrap_or(n).to_string()),
Term::Con(f, ks) => OTerm::Con(f.clone(), ks.iter().map(OTerm::lift).collect()),
Term::Leaf(p) => OTerm::Leaf(p.to_string()),
}
}
}