@@ -14,8 +14,8 @@ import Debug.Trace
1414data CaseDef = CaseDef [Name] !SC [Term]
1515 deriving Show
1616
17−data SC' t = Case Name [CaseAlt' t] -- ^ invariant: lowest tags first
18− | ProjCase t [CaseAlt' t] -- ^ special case for projections
17+data SC' t = Case Name [CaseAlt' t] -- ^ invariant: lowest tags first
18+ | ProjCase t (CaseAlt' t) -- ^ special case for projections
1919 | STerm !t
2020 | UnmatchedCase String -- ^ error message
2121 | ImpossibleCase -- ^ already checked to be impossible
@@ -45,8 +45,8 @@ instance Show t => Show (SC' t) where
4545 where
4646 show' i (Case n alts) = "case " ++ show n ++ " of\n" ++ indent i ++
4747 showSep ("\n" ++ indent i) (map (showA i) alts)
48− show' i (ProjCase tm alts) = "case " ++ show tm ++ " of " ++
49− showSep ("\n" ++ indent i) (map (showA i) alts)
48+ show' i (ProjCase tm alt) = "case " ++ show tm ++ " of " ++
49+ showSep ("\n" ++ indent i) (map (showA i) [alt])
5050 show' i (STerm tm) = show tm
5151 show' i (UnmatchedCase str) = "error " ++ show str
5252 show' i ImpossibleCase = "impossible"
@@ -96,8 +96,7 @@ small n args t = let as = findAllUsedArgs t args in
9696namesUsed :: SC -> [Name]
9797namesUsed sc = nub $ nu' [] sc where
9898 nu' ps (Case n alts) = nub (concatMap (nua ps) alts) \\ [n]
99− nu' ps (ProjCase t alts) = nub $ (nut ps t ++
100− (concatMap (nua ps) alts))
99+ nu' ps (ProjCase t alt) = nub $ nut ps t ++ nua ps alt
101100 nu' ps (STerm t) = nub $ nut ps t
102101 nu' ps _ = []
103102
@@ -122,7 +121,7 @@ namesUsed sc = nub $ nu' [] sc where
122121findCalls :: SC -> [Name] -> [(Name, [[Name]])]
123122findCalls sc topargs = nub $ nu' topargs sc where
124123 nu' ps (Case n alts) = nub (concatMap (nua (n : ps)) alts)
125− nu' ps (ProjCase t alts) = nub (nut ps t ++ concatMap (nua ps) alts)
124+ nu' ps (ProjCase t alt) = nub (nut ps t ++ nua ps alt)
126125 nu' ps (STerm t) = nub $ nut ps t
127126 nu' ps _ = []
128127
@@ -175,7 +174,7 @@ findUsedArgs sc topargs = nub (findAllUsedArgs sc topargs)
175174
176175findAllUsedArgs sc topargs = filter (\x -> x `elem` topargs) (nu' sc) where
177176 nu' (Case n alts) = n : concatMap nua alts
178− nu' (ProjCase t alts) = directUse t ++ concatMap nua alts
177+ nu' (ProjCase t alt) = directUse t ++ nua alt
179178 nu' (STerm t) = directUse t
180179 nu' _ = []
181180
@@ -640,12 +639,12 @@ prune proj (Case n alts)
640639-- projn t = t
641640
642641 projRep :: Name -> Name -> Int -> SC -> SC
642+ projRep arg n i (Case x [alt]) | x == arg
643+ = ProjCase (Proj (P Bound n Erased) i) (projRepAlt arg n i alt)
643644 projRep arg n i (Case x alts)
644− | x == arg = ProjCase (Proj (P Bound n Erased) i)
645− (map (projRepAlt arg n i) alts)
646− | otherwise = Case x (map (projRepAlt arg n i) alts)
647− projRep arg n i (ProjCase t alts)
648− = ProjCase (projRepTm arg n i t) (map (projRepAlt arg n i) alts)
645+ = Case x (map (projRepAlt arg n i) alts)
646+ projRep arg n i (ProjCase t alt)
647+ = ProjCase (projRepTm arg n i t) (projRepAlt arg n i alt)
649648 projRep arg n i (STerm t) = STerm (projRepTm arg n i t)
650649 projRep arg n i c = c -- unmatched
651650