pub fn read_back_neutral(
    prims: &prim::Env,
    metas: &meta::Env,
    size: var::Size,
    head: &Head,
    spine: &Spine,
) -> Result<Rc<Term>, String> {
    let (head, spine) = match head {
        Head::Var(var_level) => (
            Rc::from(Term::var(size.index(*var_level))),
            spine.as_slice(),
        ),
        Head::Meta(meta_index) => (Rc::from(Term::meta(*meta_index)), spine.as_slice()),
        Head::Prim(prim_name) => {
            let (value, spine) = eval_prim(prims, prim_name, &spine)?;
            (read_back_value(prims, metas, size, &value)?, spine)
        },
    };

    spine.iter().fold(Ok(head), |acc, elim| match elim {
        Elim::Literal(closure) => {
            let clauses = Rc::from(
                closure
                    .clauses
                    .iter()
                    .map(|(literal_intro, body)| {
                        let body = eval_term(prims, metas, &closure.values, body)?;
                        let body = read_back_value(prims, metas, size, &body)?;
                        Ok((literal_intro.clone(), body))
                    })
                    .collect::<Result<Vec<_>, String>>()?,
            );
            let default_body = eval_term(prims, metas, &closure.values, &closure.default)?;
            let default_body = read_back_value(prims, metas, size, &default_body)?;

            Ok(Rc::from(Term::LiteralElim(acc?, clauses, default_body)))
        },
        Elim::Fun(app_mode, arg) => {
            let arg = read_back_value(prims, metas, size, &arg)?;

            Ok(Rc::from(Term::FunElim(acc?, app_mode.clone(), arg)))
        },
        Elim::Record(label) => Ok(Rc::from(Term::RecordElim(acc?, label.clone()))),
    })
}
/// Read a neutral value back into the core syntax, normalizing as required.
Read a neutral value back into the core syntax, normalizing as required.
Read a neutral value back into the core syntax normalizing as required .
pub fn read_back_neutral(
    prims: &prim::Env,
    metas: &meta::Env,
    size: var::Size,
    head: &Head,
    spine: &Spine,
) -> Result<Rc<Term>, String> {
    let (head, spine) = match head {
        Head::Var(var_level) => (
            Rc::from(Term::var(size.index(*var_level))),
            spine.as_slice(),
        ),
        Head::Meta(meta_index) => (Rc::from(Term::meta(*meta_index)), spine.as_slice()),
        Head::Prim(prim_name) => {
            let (value, spine) = eval_prim(prims, prim_name, &spine)?;
            (read_back_value(prims, metas, size, &value)?, spine)
        },
    };
    spine.iter().fold(Ok(head), |acc, elim| match elim {
        Elim::Literal(closure) => {
            let clauses = Rc::from(
                closure
                    .clauses
                    .iter()
                    .map(|(literal_intro, body)| {
                        let body = eval_term(prims, metas, &closure.values, body)?;
                        let body = read_back_value(prims, metas, size, &body)?;
                        Ok((literal_intro.clone(), body))
                    })
                    .collect::<Result<Vec<_>, String>>()?,
            );
            let default_body = eval_term(prims, metas, &closure.values, &closure.default)?;
            let default_body = read_back_value(prims, metas, size, &default_body)?;
            Ok(Rc::from(Term::LiteralElim(acc?, clauses, default_body)))
        },
        Elim::Fun(app_mode, arg) => {
            let arg = read_back_value(prims, metas, size, &arg)?;
            Ok(Rc::from(Term::FunElim(acc?, app_mode.clone(), arg)))
        },
        Elim::Record(label) => Ok(Rc::from(Term::RecordElim(acc?, label.clone()))),
    })
}
pub fn read_back_neutral ( prims : & prim :: Env , metas : & meta :: Env , size : var :: Size , head : & Head , spine : & Spine , ) -> Result < Rc < Term > , String > { let ( head , spine ) = match head { Head :: Var ( var_level ) => ( Rc :: from ( Term :: var ( size . index ( * var_level ) ) ) , spine . as_slice ( ) , ) , Head :: Meta ( meta_index ) => ( Rc :: from ( Term :: meta ( * meta_index ) ) , spine . as_slice ( ) ) , Head :: Prim ( prim_name ) => { let ( value , spine ) = eval_prim ( prims , prim_name , & spine ) ? ; ( read_back_value ( prims , metas , size , & value ) ? , spine ) } , } ; spine . iter ( ) . fold ( Ok ( head ) , | acc , elim | match elim { Elim :: Literal ( closure ) => { let clauses = Rc :: from ( closure . clauses . iter ( ) . map ( | ( literal_intro , body ) | { let body = eval_term ( prims , metas , & closure . values , body ) ? ; let body = read_back_value ( prims , metas , size , & body ) ? ; Ok ( ( literal_intro . clone ( ) , body ) ) } ) . collect :: < Result < Vec < _ > , String > > ( ) ? , ) ; let default_body = eval_term ( prims , metas , & closure . values , & closure . default ) ? ; let default_body = read_back_value ( prims , metas , size , & default_body ) ? ; Ok ( Rc :: from ( Term :: LiteralElim ( acc ? , clauses , default_body ) ) ) } , Elim :: Fun ( app_mode , arg ) => { let arg = read_back_value ( prims , metas , size , & arg ) ? ; Ok ( Rc :: from ( Term :: FunElim ( acc ? , app_mode . clone ( ) , arg ) ) ) } , Elim :: Record ( label ) => Ok ( Rc :: from ( Term :: RecordElim ( acc ? , label . clone ( ) ) ) ) , } ) }
Read a neutral value back into the core syntax, normalizing as required.
Read a neutral value back into the core syntax normalizing as required .
prims
&prim::Env
metas
&meta::Env
size
var::Size
head
&Head
spine
&Spine
prims
&prim::Env
metas
&meta::Env
size
var::Size
head
&Head
spine
&Spine