pub fn match_value(
    context: &Context,
    pattern: &RcPattern,
    value: &RcValue,
) -> Result<Option<Vec<(FreeVar<String>, RcValue)>>, InternalError> {
    match (&*pattern.inner, &*value.inner) {
        (&Pattern::Binder(Binder(ref free_var)), _) => {
            Ok(Some(vec![(free_var.clone(), value.clone())]))
        },
        (&Pattern::Var(Embed(Var::Free(ref free_var))), _) => match context
            .get_definition(free_var)
            .and_then(|definition| match definition {
                Definition::Alias(ref term) => Some(nf_term(context, term)),
                Definition::IntersectionType(_)
                | Definition::StructType(_)
                | Definition::UnionType(_) => None,
            }) {
            Some(Ok(ref term)) if term == value => Ok(Some(vec![])),
            Some(Ok(_)) | None => Ok(None),
            Some(Err(err)) => Err(err),
        },
        (&Pattern::Literal(ref pattern_lit), &Value::Literal(ref value_lit))
            if pattern_lit == value_lit =>
        {
            Ok(Some(vec![]))
        },
        (_, _) => Ok(None),
    }
}
/// If the pattern matches the value, this function returns the substitutions
/// needed to apply the pattern to some body expression
If the pattern matches the value, this function returns the substitutions
needed to apply the pattern to some body expression
If the pattern matches the value this function returns the substitutions needed to apply the pattern to some body expression
pub fn match_value(
    context: &Context,
    pattern: &RcPattern,
    value: &RcValue,
) -> Result<Option<Vec<(FreeVar<String>, RcValue)>>, InternalError> {
    match (&*pattern.inner, &*value.inner) {
        (&Pattern::Binder(Binder(ref free_var)), _) => {
            Ok(Some(vec![(free_var.clone(), value.clone())]))
        },
        (&Pattern::Var(Embed(Var::Free(ref free_var))), _) => match context
            .get_definition(free_var)
            .and_then(|definition| match definition {
                Definition::Alias(ref term) => Some(nf_term(context, term)),
                Definition::IntersectionType(_)
                | Definition::StructType(_)
                | Definition::UnionType(_) => None,
            }) {
            Some(Ok(ref term)) if term == value => Ok(Some(vec![])),
            Some(Ok(_)) | None => Ok(None),
            Some(Err(err)) => Err(err),
        },
        (&Pattern::Literal(ref pattern_lit), &Value::Literal(ref value_lit))
            if pattern_lit == value_lit =>
        {
            Ok(Some(vec![]))
        },
        (_, _) => Ok(None),
    }
}
pub fn match_value ( context : & Context , pattern : & RcPattern , value : & RcValue , ) -> Result < Option < Vec < ( FreeVar < String > , RcValue ) > > , InternalError > { match ( & * pattern . inner , & * value . inner ) { ( & Pattern :: Binder ( Binder ( ref free_var ) ) , _ ) => { Ok ( Some ( vec ! [ ( free_var clone ( ) value clone ( ) ) ] ) ) } , ( & Pattern :: Var ( Embed ( Var :: Free ( ref free_var ) ) ) , _ ) => match context . get_definition ( free_var ) . and_then ( | definition | match definition { Definition :: Alias ( ref term ) => Some ( nf_term ( context , term ) ) , Definition :: IntersectionType ( _ ) | Definition :: StructType ( _ ) | Definition :: UnionType ( _ ) => None , } ) { Some ( Ok ( ref term ) ) if term == value => Ok ( Some ( vec ! [ ] ) ) , Some ( Ok ( _ ) ) | None => Ok ( None ) , Some ( Err ( err ) ) => Err ( err ) , } , ( & Pattern :: Literal ( ref pattern_lit ) , & Value :: Literal ( ref value_lit ) ) if pattern_lit == value_lit => { Ok ( Some ( vec ! [ ] ) ) } , ( _ , _ ) => Ok ( None ) , } }
If the pattern matches the value, this function returns the substitutions
needed to apply the pattern to some body expression
If the pattern matches the value this function returns the substitutions needed to apply the pattern to some body expression
context
&Context
pattern
&RcPattern
value
&RcValue
context
&Context
pattern
&RcPattern
value
&RcValue