pub fn read_back_neutral(level: VarLevel, head: Head, spine: &Spine) -> Result<RcTerm, NbeError> {
    let head = match head {
        Head::Var(var_level) => RcTerm::from(Term::Var(VarIndex(level.0 - (var_level.0 + 1)))),
    };

    spine.iter().fold(Ok(head), |acc, elim| match elim {
        Elim::Literal(clauses, default_body) => {
            let clauses = clauses
                .clauses
                .iter()
                .map(|(literal_intro, body)| {
                    let body = read_back_term(level, &eval(body, &clauses.env)?)?;
                    Ok((literal_intro.clone(), body))
                })
                .collect::<Result<Vec<_>, _>>()?;
            let default_param = RcValue::var(level);
            let default_body =
                read_back_term(level + 1, &do_closure_app(default_body, default_param)?)?;

            Ok(RcTerm::from(Term::LiteralElim(
                acc?,
                clauses.into(),
                default_body,
            )))
        },
        Elim::Fun(app_mode, arg) => Ok(RcTerm::from(Term::FunElim(
            acc?,
            app_mode.clone(),
            read_back_term(level, arg)?,
        ))),
        Elim::Record(label) => Ok(RcTerm::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(level: VarLevel, head: Head, spine: &Spine) -> Result<RcTerm, NbeError> {
    let head = match head {
        Head::Var(var_level) => RcTerm::from(Term::Var(VarIndex(level.0 - (var_level.0 + 1)))),
    };
    spine.iter().fold(Ok(head), |acc, elim| match elim {
        Elim::Literal(clauses, default_body) => {
            let clauses = clauses
                .clauses
                .iter()
                .map(|(literal_intro, body)| {
                    let body = read_back_term(level, &eval(body, &clauses.env)?)?;
                    Ok((literal_intro.clone(), body))
                })
                .collect::<Result<Vec<_>, _>>()?;
            let default_param = RcValue::var(level);
            let default_body =
                read_back_term(level + 1, &do_closure_app(default_body, default_param)?)?;
            Ok(RcTerm::from(Term::LiteralElim(
                acc?,
                clauses.into(),
                default_body,
            )))
        },
        Elim::Fun(app_mode, arg) => Ok(RcTerm::from(Term::FunElim(
            acc?,
            app_mode.clone(),
            read_back_term(level, arg)?,
        ))),
        Elim::Record(label) => Ok(RcTerm::from(Term::RecordElim(acc?, label.clone()))),
    })
}
pub fn read_back_neutral ( level : VarLevel , head : Head , spine : & Spine ) -> Result < RcTerm , NbeError > { let head = match head { Head :: Var ( var_level ) => RcTerm :: from ( Term :: Var ( VarIndex ( level . 0 - ( var_level . 0 + 1 ) ) ) ) , } ; spine . iter ( ) . fold ( Ok ( head ) , | acc , elim | match elim { Elim :: Literal ( clauses , default_body ) => { let clauses = clauses . clauses . iter ( ) . map ( | ( literal_intro , body ) | { let body = read_back_term ( level , & eval ( body , & clauses . env ) ? ) ? ; Ok ( ( literal_intro . clone ( ) , body ) ) } ) . collect :: < Result < Vec < _ > , _ > > ( ) ? ; let default_param = RcValue :: var ( level ) ; let default_body = read_back_term ( level + 1 , & do_closure_app ( default_body , default_param ) ? ) ? ; Ok ( RcTerm :: from ( Term :: LiteralElim ( acc ? , clauses . into ( ) , default_body , ) ) ) } , Elim :: Fun ( app_mode , arg ) => Ok ( RcTerm :: from ( Term :: FunElim ( acc ? , app_mode . clone ( ) , read_back_term ( level , arg ) ? , ) ) ) , Elim :: Record ( label ) => Ok ( RcTerm :: 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 .
level
VarLevel
head
Head
spine
&Spine