pub fn infer_pattern(
    context: &Context,
    raw_pattern: &raw::RcPattern,
) -> Result<(RcPattern, RcType, Vec<(FreeVar<String>, RcType)>), TypeError> {
    match *raw_pattern.inner {
        raw::Pattern::Ann(ref raw_pattern, Embed(ref raw_ty)) => {
            let (ty, _) = infer_universe(context, raw_ty)?;
            let value_ty = nf_term(context, &ty)?;
            let (pattern, declarations) = check_pattern(context, raw_pattern, &value_ty)?;

            Ok((
                RcPattern::from(Pattern::Ann(pattern, Embed(ty))),
                value_ty,
                declarations,
            ))
        },
        raw::Pattern::Binder(span, ref binder) => Err(TypeError::BinderNeedsAnnotation {
            span,
            binder: binder.clone(),
        }),
        raw::Pattern::Var(span, Embed(ref var)) => match *var {
            Var::Free(ref free_var) => match context.get_declaration(free_var) {
                Some(ty) => Ok((
                    RcPattern::from(Pattern::Var(Embed(var.clone()))),
                    ty.clone(),
                    vec![],
                )),
                None => Err(TypeError::UndefinedName {
                    span,
                    free_var: free_var.clone(),
                }),
            },

            // We should always be substituting bound variables with fresh
            // variables when entering scopes using `unbind`, so if we've
            // encountered one here this is definitely a bug!
            Var::Bound(_) => Err(InternalError::UnexpectedBoundVar {
                span: Some(raw_pattern.span()),
                var: var.clone(),
            }
            .into()),
        },
        raw::Pattern::Literal(ref literal) => {
            let (pattern, ty) = infer_literal(context, literal, |lit| {
                RcPattern::from(Pattern::Literal(lit))
            })?;
            Ok((pattern, ty, vec![]))
        },
    }
}
/// Synthesize the type of a pattern, returning the elaborated pattern, the
/// inferred type, and a vector of the declarations it introduced if successful
Synthesize the type of a pattern, returning the elaborated pattern, the
inferred type, and a vector of the declarations it introduced if successful
Synthesize the type of a pattern returning the elaborated pattern the inferred type and a vector of the declarations it introduced if successful
pub fn infer_pattern(
    context: &Context,
    raw_pattern: &raw::RcPattern,
) -> Result<(RcPattern, RcType, Vec<(FreeVar<String>, RcType)>), TypeError> {
    match *raw_pattern.inner {
        raw::Pattern::Ann(ref raw_pattern, Embed(ref raw_ty)) => {
            let (ty, _) = infer_universe(context, raw_ty)?;
            let value_ty = nf_term(context, &ty)?;
            let (pattern, declarations) = check_pattern(context, raw_pattern, &value_ty)?;
            Ok((
                RcPattern::from(Pattern::Ann(pattern, Embed(ty))),
                value_ty,
                declarations,
            ))
        },
        raw::Pattern::Binder(span, ref binder) => Err(TypeError::BinderNeedsAnnotation {
            span,
            binder: binder.clone(),
        }),
        raw::Pattern::Var(span, Embed(ref var)) => match *var {
            Var::Free(ref free_var) => match context.get_declaration(free_var) {
                Some(ty) => Ok((
                    RcPattern::from(Pattern::Var(Embed(var.clone()))),
                    ty.clone(),
                    vec![],
                )),
                None => Err(TypeError::UndefinedName {
                    span,
                    free_var: free_var.clone(),
                }),
            },
            // We should always be substituting bound variables with fresh
            // variables when entering scopes using `unbind`, so if we've
            // encountered one here this is definitely a bug!
            Var::Bound(_) => Err(InternalError::UnexpectedBoundVar {
                span: Some(raw_pattern.span()),
                var: var.clone(),
            }
            .into()),
        },
        raw::Pattern::Literal(ref literal) => {
            let (pattern, ty) = infer_literal(context, literal, |lit| {
                RcPattern::from(Pattern::Literal(lit))
            })?;
            Ok((pattern, ty, vec![]))
        },
    }
}
pub fn infer_pattern ( context : & Context , raw_pattern : & raw :: RcPattern , ) -> Result < ( RcPattern , RcType , Vec < ( FreeVar < String > , RcType ) > ) , TypeError > { match * raw_pattern . inner { raw :: Pattern :: Ann ( ref raw_pattern , Embed ( ref raw_ty ) ) => { let ( ty , _ ) = infer_universe ( context , raw_ty ) ? ; let value_ty = nf_term ( context , & ty ) ? ; let ( pattern , declarations ) = check_pattern ( context , raw_pattern , & value_ty ) ? ; Ok ( ( RcPattern :: from ( Pattern :: Ann ( pattern , Embed ( ty ) ) ) , value_ty , declarations , ) ) } , raw :: Pattern :: Binder ( span , ref binder ) => Err ( TypeError :: BinderNeedsAnnotation { span , binder : binder . clone ( ) , } ) , raw :: Pattern :: Var ( span , Embed ( ref var ) ) => match * var { Var :: Free ( ref free_var ) => match context . get_declaration ( free_var ) { Some ( ty ) => Ok ( ( RcPattern :: from ( Pattern :: Var ( Embed ( var . clone ( ) ) ) ) , ty . clone ( ) , vec ! [ ] , ) ) , None => Err ( TypeError :: UndefinedName { span , free_var : free_var . clone ( ) , } ) , } , // We should always be substituting bound variables with fresh // variables when entering scopes using `unbind`, so if we've // encountered one here this is definitely a bug! Var :: Bound ( _ ) => Err ( InternalError :: UnexpectedBoundVar { span : Some ( raw_pattern . span ( ) ) , var : var . clone ( ) , } . into ( ) ) , } , raw :: Pattern :: Literal ( ref literal ) => { let ( pattern , ty ) = infer_literal ( context , literal , | lit | { RcPattern :: from ( Pattern :: Literal ( lit ) ) } ) ? ; Ok ( ( pattern , ty , vec ! [ ] ) ) } , } }
Synthesize the type of a pattern, returning the elaborated pattern, the
inferred type, and a vector of the declarations it introduced if successful
Synthesize the type of a pattern returning the elaborated pattern the inferred type and a vector of the declarations it introduced if successful
context
&Context
raw_pattern
&raw::RcPattern
context
&Context
raw_pattern
&raw::RcPattern