pub fn check_merge_type(
    index: u32,
    mut tcs: TCS,
    left: Expression,
    right: Expression,
) -> TCM<(Level, TCS)> {
    let (left_level, new_tcs) = check_type(index, tcs, left.clone())?;
    tcs = new_tcs;
    let (right_level, new_tcs) = check_type(index, tcs, right.clone())?;
    tcs = new_tcs;
    let left_branches = match left.clone().eval_to_sum(tcs.context()) {
        Some(branches) => branches,
        None => return Err(TCE::WantSumBut(Either::Right(left))),
    };
    let right_branches = match right.clone().eval_to_sum(tcs.context()) {
        Some(branches) => branches,
        None => return Err(TCE::WantSumBut(Either::Right(right))),
    };
    for left_branch in left_branches.into_iter() {
        if right_branches.contains(&left_branch) {
            return Err(TCE::DuplicateBranch(left_branch));
        }
    }
    Ok((max(left_level, right_level), tcs))
}
/// To reuse code that checks if a merge expression is well-typed between `check_type` and `check`
To reuse code that checks if a merge expression is well-typed between `check_type` and `check`
To reuse code that checks if a merge expression is well - typed between ` check_type ` and ` check `
pub fn check_merge_type(
    index: u32,
    mut tcs: TCS,
    left: Expression,
    right: Expression,
) -> TCM<(Level, TCS)> {
    let (left_level, new_tcs) = check_type(index, tcs, left.clone())?;
    tcs = new_tcs;
    let (right_level, new_tcs) = check_type(index, tcs, right.clone())?;
    tcs = new_tcs;
    let left_branches = match left.clone().eval_to_sum(tcs.context()) {
        Some(branches) => branches,
        None => return Err(TCE::WantSumBut(Either::Right(left))),
    };
    let right_branches = match right.clone().eval_to_sum(tcs.context()) {
        Some(branches) => branches,
        None => return Err(TCE::WantSumBut(Either::Right(right))),
    };
    for left_branch in left_branches.into_iter() {
        if right_branches.contains(&left_branch) {
            return Err(TCE::DuplicateBranch(left_branch));
        }
    }
    Ok((max(left_level, right_level), tcs))
}
pub fn check_merge_type ( index : u32 , mut tcs : TCS , left : Expression , right : Expression , ) -> TCM < ( Level , TCS ) > { let ( left_level , new_tcs ) = check_type ( index , tcs , left . clone ( ) ) ? ; tcs = new_tcs ; let ( right_level , new_tcs ) = check_type ( index , tcs , right . clone ( ) ) ? ; tcs = new_tcs ; let left_branches = match left . clone ( ) . eval_to_sum ( tcs . context ( ) ) { Some ( branches ) => branches , None => return Err ( TCE :: WantSumBut ( Either :: Right ( left ) ) ) , } ; let right_branches = match right . clone ( ) . eval_to_sum ( tcs . context ( ) ) { Some ( branches ) => branches , None => return Err ( TCE :: WantSumBut ( Either :: Right ( right ) ) ) , } ; for left_branch in left_branches . into_iter ( ) { if right_branches . contains ( & left_branch ) { return Err ( TCE :: DuplicateBranch ( left_branch ) ) ; } } Ok ( ( max ( left_level , right_level ) , tcs ) ) }
To reuse code that checks if a merge expression is well-typed between `check_type` and `check`
To reuse code that checks if a merge expression is well - typed between ` check_type ` and ` check `
index
u32
tcs
TCS
left
Expression
right
Expression
index
u32
tcs
TCS
left
Expression
right
Expression