@@ -1,6 +1,8 @@
1{-# LANGUAGE PatternGuards #-}
1{-# LANGUAGE PatternGuards #-}
3−module Idris.CaseSplit(split, splitOnLine, replaceSplits, getClause) where
3+module Idris.CaseSplit(split, splitOnLine, replaceSplits,
5-- splitting a variable in a pattern clause
7-- splitting a variable in a pattern clause
@@ -59,6 +61,7 @@ split n t'
59 do let splits = findPats ist ty
61 do let splits = findPats ist ty
60 iLOG ("New patterns " ++ show splits)
62 iLOG ("New patterns " ++ show splits)
61 let newPats_in = zipWith (replaceVar ctxt n) splits (repeat t)
63 let newPats_in = zipWith (replaceVar ctxt n) splits (repeat t)
64+ logLvl 4 ("Working from " ++ show t)
62 logLvl 4 ("Trying " ++ showSep "\n" (map show newPats_in))
65 logLvl 4 ("Trying " ++ showSep "\n" (map show newPats_in))
63 newPats <- mapM elabNewPat newPats_in
66 newPats <- mapM elabNewPat newPats_in
64 logLvl 3 ("Original:\n" ++ show t)
67 logLvl 3 ("Original:\n" ++ show t)
@@ -95,8 +98,8 @@ mergePat ctxt (PPatvar fc n) new
95mergePat ctxt old (PPatvar fc n)
98mergePat ctxt old (PPatvar fc n)
96 = mergePat ctxt old (PRef fc n)
99 = mergePat ctxt old (PRef fc n)
97mergePat ctxt orig@(PRef fc n) new@(PRef _ n')
100mergePat ctxt orig@(PRef fc n) new@(PRef _ n')
98− | isConName n' ctxt = do addUpdate n new;
101+ | isDConName n' ctxt = do addUpdate n new;
99− return new
102+ return new
100 | otherwise
103 | otherwise
101 = do ms <- get
104 = do ms <- get
102 case lookup n' (namemap ms) of
105 case lookup n' (namemap ms) of
@@ -164,9 +167,10 @@ replaceVar ctxt n t (PApp fc f pats) = PApp fc f (map substArg pats)
164 subst orig@(PPatvar _ v) | v == n = t
167 subst orig@(PPatvar _ v) | v == n = t
165 | otherwise = Placeholder
168 | otherwise = Placeholder
166 subst orig@(PRef _ v) | v == n = t
169 subst orig@(PRef _ v) | v == n = t
167− | isConName v ctxt = orig
170+ | isDConName v ctxt = orig
168 subst (PRef _ _) = Placeholder
171 subst (PRef _ _) = Placeholder
169 subst (PApp fc f pats) = PApp fc f (map substArg pats)
172 subst (PApp fc f pats) = PApp fc f (map substArg pats)
173+ subst (PEq fc l r) = PEq fc (subst l) (subst r)
170 subst x = x
174 subst x = x
172 substArg arg = arg { getTm = subst (getTm arg) }
176 substArg arg = arg { getTm = subst (getTm arg) }
@@ -239,7 +243,22 @@ getClause l fn fp = do ty <- getInternalApp fp l
239 mkApp (PPi _ _ _ sc) ns = mkApp sc ns
243 mkApp (PPi _ _ _ sc) ns = mkApp sc ns
240 mkApp _ _ = ""
244 mkApp _ _ = ""
242−
246+-- Purely syntactic - turn a pattern match clause into a with and a new
249+mkWith :: String -> Name -> String
250+mkWith str n = let ind = getIndent str
251+ str' = replicate ind ' ' ++
252+ replaceRHS str "with (_)"
253+ newpat = replicate (ind + 2) ' ' ++
254+ replaceRHS str "| with_pat = ?" ++ show n ++ "_rhs" in
255+ str' ++ "\n" ++ newpat
257+ where getIndent s = length (takeWhile isSpace s)
259+ replaceRHS [] str = str
260+ replaceRHS ('?':'=': rest) str = str
261+ replaceRHS ('=': rest) str = str
262+ replaceRHS (x : rest) str = x : replaceRHS rest str