pub fn read_back_term(level: VarLevel, term: &RcValue) -> Result<RcTerm, NbeError> {
    match term.as_ref() {
        Value::Neutral(head, spine) => read_back_neutral(level, *head, spine),

        // Literals
        Value::LiteralType(literal_ty) => Ok(RcTerm::from(Term::LiteralType(literal_ty.clone()))),
        Value::LiteralIntro(literal_intro) => {
            Ok(RcTerm::from(Term::LiteralIntro(literal_intro.clone())))
        },

        // Functions
        Value::FunType(app_mode, param_ty, body_ty) => {
            let app_mode = app_mode.clone();
            let param = RcValue::var(level);
            let param_ty = read_back_term(level, param_ty)?;
            let body_ty = read_back_term(level + 1, &do_closure_app(body_ty, param)?)?;

            Ok(RcTerm::from(Term::FunType(app_mode, param_ty, body_ty)))
        },
        Value::FunIntro(app_mode, body) => {
            let app_mode = app_mode.clone();
            let param = RcValue::var(level);
            let body = read_back_term(level + 1, &do_closure_app(body, param)?)?;

            Ok(RcTerm::from(Term::FunIntro(app_mode, body)))
        },

        // Records
        Value::RecordTypeExtend(doc, label, term_ty, rest_ty) => {
            let mut level = level;

            let term = RcValue::var(level);
            let term_ty = read_back_term(level, term_ty)?;

            let mut rest_ty = do_closure_app(rest_ty, term)?;
            let mut field_tys = vec![(doc.clone(), label.clone(), term_ty)];

            while let Value::RecordTypeExtend(next_doc, next_label, next_term_ty, next_rest_ty) =
                rest_ty.as_ref()
            {
                level += 1;
                let next_term = RcValue::var(level);
                let next_term_ty = read_back_term(level, next_term_ty)?;

                field_tys.push((next_doc.clone(), next_label.clone(), next_term_ty));
                rest_ty = do_closure_app(next_rest_ty, next_term)?;
            }

            Ok(RcTerm::from(Term::RecordType(field_tys)))
        },
        Value::RecordTypeEmpty => Ok(RcTerm::from(Term::RecordType(Vec::new()))),
        Value::RecordIntro(fields) => {
            let fields = fields
                .iter()
                .map(|(label, term)| Ok((label.clone(), read_back_term(level, term)?)))
                .collect::<Result<_, _>>()?;

            Ok(RcTerm::from(Term::RecordIntro(fields)))
        },

        // Universes
        Value::Universe(level) => Ok(RcTerm::from(Term::Universe(*level))),
    }
}
/// Read a value back into the core syntax, normalizing as required.
Read a value back into the core syntax, normalizing as required.
Read a value back into the core syntax normalizing as required .
pub fn read_back_term(level: VarLevel, term: &RcValue) -> Result<RcTerm, NbeError> {
    match term.as_ref() {
        Value::Neutral(head, spine) => read_back_neutral(level, *head, spine),
        // Literals
        Value::LiteralType(literal_ty) => Ok(RcTerm::from(Term::LiteralType(literal_ty.clone()))),
        Value::LiteralIntro(literal_intro) => {
            Ok(RcTerm::from(Term::LiteralIntro(literal_intro.clone())))
        },
        // Functions
        Value::FunType(app_mode, param_ty, body_ty) => {
            let app_mode = app_mode.clone();
            let param = RcValue::var(level);
            let param_ty = read_back_term(level, param_ty)?;
            let body_ty = read_back_term(level + 1, &do_closure_app(body_ty, param)?)?;
            Ok(RcTerm::from(Term::FunType(app_mode, param_ty, body_ty)))
        },
        Value::FunIntro(app_mode, body) => {
            let app_mode = app_mode.clone();
            let param = RcValue::var(level);
            let body = read_back_term(level + 1, &do_closure_app(body, param)?)?;
            Ok(RcTerm::from(Term::FunIntro(app_mode, body)))
        },
        // Records
        Value::RecordTypeExtend(doc, label, term_ty, rest_ty) => {
            let mut level = level;
            let term = RcValue::var(level);
            let term_ty = read_back_term(level, term_ty)?;
            let mut rest_ty = do_closure_app(rest_ty, term)?;
            let mut field_tys = vec![(doc.clone(), label.clone(), term_ty)];
            while let Value::RecordTypeExtend(next_doc, next_label, next_term_ty, next_rest_ty) =
                rest_ty.as_ref()
            {
                level += 1;
                let next_term = RcValue::var(level);
                let next_term_ty = read_back_term(level, next_term_ty)?;
                field_tys.push((next_doc.clone(), next_label.clone(), next_term_ty));
                rest_ty = do_closure_app(next_rest_ty, next_term)?;
            }
            Ok(RcTerm::from(Term::RecordType(field_tys)))
        },
        Value::RecordTypeEmpty => Ok(RcTerm::from(Term::RecordType(Vec::new()))),
        Value::RecordIntro(fields) => {
            let fields = fields
                .iter()
                .map(|(label, term)| Ok((label.clone(), read_back_term(level, term)?)))
                .collect::<Result<_, _>>()?;
            Ok(RcTerm::from(Term::RecordIntro(fields)))
        },
        // Universes
        Value::Universe(level) => Ok(RcTerm::from(Term::Universe(*level))),
    }
}
pub fn read_back_term ( level : VarLevel , term : & RcValue ) -> Result < RcTerm , NbeError > { match term . as_ref ( ) { Value :: Neutral ( head , spine ) => read_back_neutral ( level , * head , spine ) , // Literals Value :: LiteralType ( literal_ty ) => Ok ( RcTerm :: from ( Term :: LiteralType ( literal_ty . clone ( ) ) ) ) , Value :: LiteralIntro ( literal_intro ) => { Ok ( RcTerm :: from ( Term :: LiteralIntro ( literal_intro . clone ( ) ) ) ) } , // Functions Value :: FunType ( app_mode , param_ty , body_ty ) => { let app_mode = app_mode . clone ( ) ; let param = RcValue :: var ( level ) ; let param_ty = read_back_term ( level , param_ty ) ? ; let body_ty = read_back_term ( level + 1 , & do_closure_app ( body_ty , param ) ? ) ? ; Ok ( RcTerm :: from ( Term :: FunType ( app_mode , param_ty , body_ty ) ) ) } , Value :: FunIntro ( app_mode , body ) => { let app_mode = app_mode . clone ( ) ; let param = RcValue :: var ( level ) ; let body = read_back_term ( level + 1 , & do_closure_app ( body , param ) ? ) ? ; Ok ( RcTerm :: from ( Term :: FunIntro ( app_mode , body ) ) ) } , // Records Value :: RecordTypeExtend ( doc , label , term_ty , rest_ty ) => { let mut level = level ; let term = RcValue :: var ( level ) ; let term_ty = read_back_term ( level , term_ty ) ? ; let mut rest_ty = do_closure_app ( rest_ty , term ) ? ; let mut field_tys = vec ! [ ( doc clone ( ) label clone ( ) term_ty ) ] ; while let Value :: RecordTypeExtend ( next_doc , next_label , next_term_ty , next_rest_ty ) = rest_ty . as_ref ( ) { level += 1 ; let next_term = RcValue :: var ( level ) ; let next_term_ty = read_back_term ( level , next_term_ty ) ? ; field_tys . push ( ( next_doc . clone ( ) , next_label . clone ( ) , next_term_ty ) ) ; rest_ty = do_closure_app ( next_rest_ty , next_term ) ? ; } Ok ( RcTerm :: from ( Term :: RecordType ( field_tys ) ) ) } , Value :: RecordTypeEmpty => Ok ( RcTerm :: from ( Term :: RecordType ( Vec :: new ( ) ) ) ) , Value :: RecordIntro ( fields ) => { let fields = fields . iter ( ) . map ( | ( label , term ) | Ok ( ( label . clone ( ) , read_back_term ( level , term ) ? ) ) ) . collect :: < Result < _ , _ > > ( ) ? ; Ok ( RcTerm :: from ( Term :: RecordIntro ( fields ) ) ) } , // Universes Value :: Universe ( level ) => Ok ( RcTerm :: from ( Term :: Universe ( * level ) ) ) , } }
Read a value back into the core syntax, normalizing as required.
Read a value back into the core syntax normalizing as required .
level
VarLevel
term
&RcValue