pub fn check_pattern<Env>(
    env: &Env,
    raw_pattern: &raw::RcPattern,
    expected_ty: &RcType,
) -> Result<(RcPattern, Vec<(FreeVar<String>, RcType)>), TypeError>
where
    Env: DeclarationEnv + DefinitionEnv,
{
    match (&*raw_pattern.inner, &*expected_ty.inner) {
        (&raw::Pattern::Binder(_, Binder(ref free_var)), _) => {
            return Ok((
                RcPattern::from(Pattern::Binder(Binder(free_var.clone()))),
                vec![(free_var.clone(), expected_ty.clone())],
            ));
        },
        (&raw::Pattern::Literal(ref raw_literal), _) => {
            let literal = check_literal(raw_literal, expected_ty)?;
            return Ok((RcPattern::from(Pattern::Literal(literal)), vec![]));
        },
        _ => {},
    }

    let (pattern, inferred_ty, declarations) = infer_pattern(env, raw_pattern)?;
    if Type::term_eq(&inferred_ty, expected_ty) {
        Ok((pattern, declarations))
    } else {
        Err(TypeError::Mismatch {
            span: raw_pattern.span(),
            found: Box::new(inferred_ty.resugar()),
            expected: Box::new(expected_ty.resugar()),
        })
    }
}
/// Checks that a pattern is compatible with the given type, returning the
/// elaborated pattern and a vector of the declarations it introduced if successful
Checks that a pattern is compatible with the given type, returning the
elaborated pattern and a vector of the declarations it introduced if successful
Checks that a pattern is compatible with the given type returning the elaborated pattern and a vector of the declarations it introduced if successful
pub fn check_pattern<Env>(
    env: &Env,
    raw_pattern: &raw::RcPattern,
    expected_ty: &RcType,
) -> Result<(RcPattern, Vec<(FreeVar<String>, RcType)>), TypeError>
where
    Env: DeclarationEnv + DefinitionEnv,
{
    match (&*raw_pattern.inner, &*expected_ty.inner) {
        (&raw::Pattern::Binder(_, Binder(ref free_var)), _) => {
            return Ok((
                RcPattern::from(Pattern::Binder(Binder(free_var.clone()))),
                vec![(free_var.clone(), expected_ty.clone())],
            ));
        },
        (&raw::Pattern::Literal(ref raw_literal), _) => {
            let literal = check_literal(raw_literal, expected_ty)?;
            return Ok((RcPattern::from(Pattern::Literal(literal)), vec![]));
        },
        _ => {},
    }
    let (pattern, inferred_ty, declarations) = infer_pattern(env, raw_pattern)?;
    if Type::term_eq(&inferred_ty, expected_ty) {
        Ok((pattern, declarations))
    } else {
        Err(TypeError::Mismatch {
            span: raw_pattern.span(),
            found: Box::new(inferred_ty.resugar()),
            expected: Box::new(expected_ty.resugar()),
        })
    }
}
pub fn check_pattern < Env > ( env : & Env , raw_pattern : & raw :: RcPattern , expected_ty : & RcType , ) -> Result < ( RcPattern , Vec < ( FreeVar < String > , RcType ) > ) , TypeError > where Env : DeclarationEnv + DefinitionEnv , { match ( & * raw_pattern . inner , & * expected_ty . inner ) { ( & raw :: Pattern :: Binder ( _ , Binder ( ref free_var ) ) , _ ) => { return Ok ( ( RcPattern :: from ( Pattern :: Binder ( Binder ( free_var . clone ( ) ) ) ) , vec ! [ ( free_var clone ( ) expected_ty clone ( ) ) ] , ) ) ; } , ( & raw :: Pattern :: Literal ( ref raw_literal ) , _ ) => { let literal = check_literal ( raw_literal , expected_ty ) ? ; return Ok ( ( RcPattern :: from ( Pattern :: Literal ( literal ) ) , vec ! [ ] ) ) ; } , _ => { } , } let ( pattern , inferred_ty , declarations ) = infer_pattern ( env , raw_pattern ) ? ; if Type :: term_eq ( & inferred_ty , expected_ty ) { Ok ( ( pattern , declarations ) ) } else { Err ( TypeError :: Mismatch { span : raw_pattern . span ( ) , found : Box :: new ( inferred_ty . resugar ( ) ) , expected : Box :: new ( expected_ty . resugar ( ) ) , } ) } }
Checks that a pattern is compatible with the given type, returning the
elaborated pattern and a vector of the declarations it introduced if successful
Checks that a pattern is compatible with the given type returning the elaborated pattern and a vector of the declarations it introduced if successful
env
&Env
raw_pattern
&raw::RcPattern
expected_ty
&RcType
env
&Env
raw_pattern
&raw::RcPattern
expected_ty
&RcType