@@ -2,7 +2,8 @@
22
33module Idris.Core.CaseTree(CaseDef(..), SC, SC'(..), CaseAlt, CaseAlt'(..),
44 Phase(..), CaseTree,
5− simpleCase, small, namesUsed, findCalls, findUsedArgs) where
5+ simpleCase, small, namesUsed, findCalls, findUsedArgs,
6+ substSC, substAlt) where
67
78import Idris.Core.TT
89
@@ -683,5 +684,18 @@ stripLambdas (CaseDef ns (STerm (Bind x (Lam _) sc)) tm)
683684stripLambdas x = x
684685
685686
686−
687−
687+substSC :: Name -> Name -> SC -> SC
688+substSC n repl (Case n' alts)
689+ | n == n' = Case repl (map (substAlt n repl) alts)
690+ | otherwise = Case n' (map (substAlt n repl) alts)
691+substSC n repl (STerm t) = STerm $ subst n (P Bound repl Erased) t
692+substSC n repl sc = error $ "unsupported in substSC: " ++ show sc
693+
694+substAlt :: Name -> Name -> CaseAlt -> CaseAlt
695+substAlt n repl (ConCase cn a ns sc) = ConCase cn a ns (substSC n repl sc)
696+substAlt n repl (FnCase fn ns sc) = FnCase fn ns (substSC n repl sc)
697+substAlt n repl (ConstCase c sc) = ConstCase c (substSC n repl sc)
698+substAlt n repl (SucCase n' sc)
699+ | n == n' = SucCase n (substSC n repl sc)
700+ | otherwise = SucCase n' (substSC n repl sc)
701+substAlt n repl (DefaultCase sc) = DefaultCase (substSC n repl sc)