-| WEBrak : WeakTypeVar -> WeakExpr -> WeakExpr
-| WEEsc : WeakTypeVar -> WeakExpr -> WeakExpr
-| WECase : forall (scrutinee:WeakExpr)
- (tbranches:CoreType)
- {n:nat}(tc:TyCon n)
- (type_params:vec CoreType n)
- (alts : Tree ??(AltCon*list WeakVar*WeakExpr)),
- WeakExpr.
-
-(* calculate the free WeakVar's in a WeakExpr *)
-Fixpoint getWeakExprFreeVars (me:WeakExpr) : list WeakExprVar :=
- match me with
- | WELit _ => nil
- | WEVar cv => cv::nil
- | WECast e co => getWeakExprFreeVars e
- | WENote n e => getWeakExprFreeVars e
- | WETyApp e t => getWeakExprFreeVars e
- | WECoApp e co => getWeakExprFreeVars e
- | WEBrak ec e => getWeakExprFreeVars e
- | WEEsc ec e => getWeakExprFreeVars e
- | WELet cv e1 e2 => mergeDistinctLists (getWeakExprFreeVars e1) (removeFromDistinctList cv (getWeakExprFreeVars e2))
- | WEApp e1 e2 => mergeDistinctLists (getWeakExprFreeVars e1) (getWeakExprFreeVars e2)
- | WELam cv e => @removeFromDistinctList _ WeakExprVarEqDecidable cv (getWeakExprFreeVars e)
- | WETyLam cv e => getWeakExprFreeVars e
- | WECoLam cv e => getWeakExprFreeVars e
-
- (* the messy fixpoints below are required by Coq's termination conditions *)
- | WECase scrutinee tbranches n tc type_params alts =>
- mergeDistinctLists (getWeakExprFreeVars scrutinee) (
- ((fix getWeakExprFreeVarsAlts (alts:Tree ??(AltCon*list WeakVar*WeakExpr)) {struct alts} : list WeakExprVar :=
- match alts with
- | T_Leaf None => nil
- | T_Leaf (Some (DEFAULT,_,e)) => getWeakExprFreeVars e
- | T_Leaf (Some (LitAlt lit,_,e)) => getWeakExprFreeVars e
- | T_Leaf (Some (DataAlt _ _ _ _ _ dc, vars,e)) => removeFromDistinctList'
- (General.filter (map (fun v => match v with
- | WExprVar ev => Some ev
- | WTypeVar _ => None
- | WCoerVar _ => None
- end) vars))
- (getWeakExprFreeVars e)
- | T_Branch b1 b2 => mergeDistinctLists (getWeakExprFreeVarsAlts b1) (getWeakExprFreeVarsAlts b2)
- end) alts))
- | WELetRec mlr e => (fix removeVarsLetRec (mlr:Tree ??(WeakExprVar * WeakExpr))(cvl:list WeakExprVar) :=
- match mlr with
- | T_Leaf None => cvl
- | T_Leaf (Some (cv,e)) => removeFromDistinctList cv cvl
- | T_Branch b1 b2 => removeVarsLetRec b1 (removeVarsLetRec b2 cvl)
- end) mlr (mergeDistinctLists (getWeakExprFreeVars e)
- ((fix getWeakExprFreeVarsLetRec (mlr:Tree ??(WeakExprVar * WeakExpr)) :=
- match mlr with
- | T_Leaf None => nil
- | T_Leaf (Some (cv,e)) => getWeakExprFreeVars e
- | T_Branch b1 b2 => mergeDistinctLists (getWeakExprFreeVarsLetRec b1) (getWeakExprFreeVarsLetRec b2)
- end) mlr))
- end.