@@ -43,7 +43,7 @@ matchSubst pairs (Match n cs m) =
4343 clauseSubst (Clause c vs m) =
4444 Clause c (map varSubst vs) (matchSubst pairs m)
4545
46−isCon (p:ps, _) =
46+isCon (p:ps, e) =
4747 case p of
4848 PData _ _ -> True
4949 PLiteral _ -> True
@@ -56,22 +56,28 @@ match [] [] def = return def
5656match [] [([],e)] Fail = return $ Other e
5757match [] [([],e)] Break = return $ Other e
5858match [] cs def = return $ Seq (map (Other . snd) cs ++ [def])
59−match vs cs def
60− | all isVar cs = matchVar vs cs def
61− | all isCon cs = matchCon vs cs def
62− | otherwise = matchMix vs cs def
59+match vs@(v:_) cs def
60+ | all isVar cs' = matchVar vs cs' def
61+ | all isCon cs' = matchCon vs cs' def
62+ | otherwise = matchMix vs cs' def
63+ where
64+ cs' = map (dealias v) cs
65+
66+dealias v c@(p:ps, L t s e) =
67+ case p of
68+ PAlias x pattern -> (pattern:ps, L t s $ subst x (Var v) e)
69+ _ -> c
6370
6471matchVar :: [String] -> [([Pattern],LExpr t v)] -> Match t v
6572 -> Unique (Match t v)
6673matchVar (v:vs) cs def = match vs (map subVar cs) def
6774 where
68− subVar (p:ps, ce@(L t s e)) = (ps, L t s $ subOnePattern p)
75+ subVar (p:ps, ce@(L t s e)) = (ps, L t s $ subOnePattern p e)
6976 where
7077 loc = L t s
71− subOnePattern pattern =
78+ subOnePattern pattern e =
7279 case pattern of
7380 PVar x -> subst x (Var v) e
74− PAlias x p -> subst x (Var v) e
7581 PAnything -> e
7682 PRecord fs ->
7783 foldr (\x -> subst x (Access (loc (Var v)) x)) e fs