pub fn check_declaration(index: u32, tcs: TCS, declaration: Declaration) -> TCM<TCS> {
    if declaration.prefix_parameters.is_empty() {
        let context = tcs.context();
        return if !declaration.is_recursive {
            check_simple_declaration(
                index,
                tcs,
                declaration.pattern.clone(),
                declaration.signature.clone(),
                declaration.body.clone(),
            )
        } else {
            check_recursive_declaration(index, tcs, declaration.clone())
        }
        .map(|gamma| TCS::new(gamma, up_dec_rc(context, declaration)));
    }
    let (pattern, signature, body) = match declaration {
        Declaration {
            pattern,
            prefix_parameters,
            signature,
            body,
            is_recursive: false,
        } => check_lift_parameters(index, tcs_borrow!(tcs), prefix_parameters, |tcs| {
            let (_, tcs) = check_type(index, tcs, signature.clone())
                .map_err(|err| try_locate!(err, pattern))?;
            let context = tcs.context();
            let tcs = check(index, tcs, body.clone(), signature.clone().eval(context))
                .map_err(|err| try_locate!(err, pattern))?;
            Ok((signature, body, tcs))
        })
        .map(|(signature, body, _)| (pattern, signature, body))?,
        declaration => {
            let pattern = declaration.pattern.clone();
            check_lift_parameters(
                index,
                tcs_borrow!(tcs),
                declaration.prefix_parameters.clone(),
                |tcs| {
                    let (_, tcs) = check_type(index, tcs, declaration.signature.clone())
                        .map_err(|err| try_locate!(err, pattern))?;
                    let pattern = pattern.clone();
                    let generated = generate_value(index);
                    let signature = declaration.signature.clone().eval(tcs.context());
                    let fake_tcs: TCS = tcs_borrow!(tcs);
                    let fake_tcs = fake_tcs
                        .update(pattern.clone(), signature.clone(), generated)
                        .map_err(|err| try_locate!(err, pattern))?;
                    check(index + 1, fake_tcs, declaration.body.clone(), signature)
                        .map_err(|err| try_locate!(err, pattern))?;
                    Ok((
                        declaration.signature.clone(),
                        declaration.body.clone(),
                        TCS::new(tcs.gamma, up_dec_rc(tcs.context, declaration)),
                    ))
                },
            )
            .map(|(signature, body, _)| (pattern, signature, body))?
        }
    };

    let TCS { gamma, context } = tcs;
    let body = body.eval(context.clone());
    update_gamma_borrow(gamma, &pattern, signature.eval(context.clone()), &body)
        .map(|gamma| TCS::new(gamma, up_var_rc(context, pattern.clone(), body)))
        .map_err(|err| try_locate!(err, pattern))
}
/// Originally `checkD` in Mini-TT, but now it's not because this implementation supports
/// prefixed parameters :)<br/>
/// Check if a declaration is well-typed and update the context.
Originally `checkD` in Mini-TT, but now it's not because this implementation supports
prefixed parameters :)
Check if a declaration is well-typed and update the context.
Originally ` checkD ` in Mini - TT but now it ' s not because this implementation supports prefixed parameters : ) Check if a declaration is well - typed and update the context .
pub fn check_declaration(index: u32, tcs: TCS, declaration: Declaration) -> TCM<TCS> {
    if declaration.prefix_parameters.is_empty() {
        let context = tcs.context();
        return if !declaration.is_recursive {
            check_simple_declaration(
                index,
                tcs,
                declaration.pattern.clone(),
                declaration.signature.clone(),
                declaration.body.clone(),
            )
        } else {
            check_recursive_declaration(index, tcs, declaration.clone())
        }
        .map(|gamma| TCS::new(gamma, up_dec_rc(context, declaration)));
    }
    let (pattern, signature, body) = match declaration {
        Declaration {
            pattern,
            prefix_parameters,
            signature,
            body,
            is_recursive: false,
        } => check_lift_parameters(index, tcs_borrow!(tcs), prefix_parameters, |tcs| {
            let (_, tcs) = check_type(index, tcs, signature.clone())
                .map_err(|err| try_locate!(err, pattern))?;
            let context = tcs.context();
            let tcs = check(index, tcs, body.clone(), signature.clone().eval(context))
                .map_err(|err| try_locate!(err, pattern))?;
            Ok((signature, body, tcs))
        })
        .map(|(signature, body, _)| (pattern, signature, body))?,
        declaration => {
            let pattern = declaration.pattern.clone();
            check_lift_parameters(
                index,
                tcs_borrow!(tcs),
                declaration.prefix_parameters.clone(),
                |tcs| {
                    let (_, tcs) = check_type(index, tcs, declaration.signature.clone())
                        .map_err(|err| try_locate!(err, pattern))?;
                    let pattern = pattern.clone();
                    let generated = generate_value(index);
                    let signature = declaration.signature.clone().eval(tcs.context());
                    let fake_tcs: TCS = tcs_borrow!(tcs);
                    let fake_tcs = fake_tcs
                        .update(pattern.clone(), signature.clone(), generated)
                        .map_err(|err| try_locate!(err, pattern))?;
                    check(index + 1, fake_tcs, declaration.body.clone(), signature)
                        .map_err(|err| try_locate!(err, pattern))?;
                    Ok((
                        declaration.signature.clone(),
                        declaration.body.clone(),
                        TCS::new(tcs.gamma, up_dec_rc(tcs.context, declaration)),
                    ))
                },
            )
            .map(|(signature, body, _)| (pattern, signature, body))?
        }
    };
    let TCS { gamma, context } = tcs;
    let body = body.eval(context.clone());
    update_gamma_borrow(gamma, &pattern, signature.eval(context.clone()), &body)
        .map(|gamma| TCS::new(gamma, up_var_rc(context, pattern.clone(), body)))
        .map_err(|err| try_locate!(err, pattern))
}
pub fn check_declaration ( index : u32 , tcs : TCS , declaration : Declaration ) -> TCM < TCS > { if declaration . prefix_parameters . is_empty ( ) { let context = tcs . context ( ) ; return if ! declaration . is_recursive { check_simple_declaration ( index , tcs , declaration . pattern . clone ( ) , declaration . signature . clone ( ) , declaration . body . clone ( ) , ) } else { check_recursive_declaration ( index , tcs , declaration . clone ( ) ) } . map ( | gamma | TCS :: new ( gamma , up_dec_rc ( context , declaration ) ) ) ; } let ( pattern , signature , body ) = match declaration { Declaration { pattern , prefix_parameters , signature , body , is_recursive : false , } => check_lift_parameters ( index , tcs_borrow ! ( tcs ) , prefix_parameters , | tcs | { let ( _ , tcs ) = check_type ( index , tcs , signature . clone ( ) ) . map_err ( | err | try_locate ! ( err pattern ) ) ? ; let context = tcs . context ( ) ; let tcs = check ( index , tcs , body . clone ( ) , signature . clone ( ) . eval ( context ) ) . map_err ( | err | try_locate ! ( err pattern ) ) ? ; Ok ( ( signature , body , tcs ) ) } ) . map ( | ( signature , body , _ ) | ( pattern , signature , body ) ) ? , declaration => { let pattern = declaration . pattern . clone ( ) ; check_lift_parameters ( index , tcs_borrow ! ( tcs ) , declaration . prefix_parameters . clone ( ) , | tcs | { let ( _ , tcs ) = check_type ( index , tcs , declaration . signature . clone ( ) ) . map_err ( | err | try_locate ! ( err pattern ) ) ? ; let pattern = pattern . clone ( ) ; let generated = generate_value ( index ) ; let signature = declaration . signature . clone ( ) . eval ( tcs . context ( ) ) ; let fake_tcs : TCS = tcs_borrow ! ( tcs ) ; let fake_tcs = fake_tcs . update ( pattern . clone ( ) , signature . clone ( ) , generated ) . map_err ( | err | try_locate ! ( err pattern ) ) ? ; check ( index + 1 , fake_tcs , declaration . body . clone ( ) , signature ) . map_err ( | err | try_locate ! ( err pattern ) ) ? ; Ok ( ( declaration . signature . clone ( ) , declaration . body . clone ( ) , TCS :: new ( tcs . gamma , up_dec_rc ( tcs . context , declaration ) ) , ) ) } , ) . map ( | ( signature , body , _ ) | ( pattern , signature , body ) ) ? } } ; let TCS { gamma , context } = tcs ; let body = body . eval ( context . clone ( ) ) ; update_gamma_borrow ( gamma , & pattern , signature . eval ( context . clone ( ) ) , & body ) . map ( | gamma | TCS :: new ( gamma , up_var_rc ( context , pattern . clone ( ) , body ) ) ) . map_err ( | err | try_locate ! ( err pattern ) ) }
Originally `checkD` in Mini-TT, but now it's not because this implementation supports
prefixed parameters :)<br/>
Check if a declaration is well-typed and update the context.
Originally ` checkD ` in Mini - TT but now it ' s not because this implementation supports prefixed parameters : ) <br / > Check if a declaration is well - typed and update the context .
index
u32
tcs
TCS
declaration
Declaration
index
u32
tcs
TCS
declaration
Declaration