@@ -1,6 +1,6 @@
11{-# LANGUAGE PatternGuards #-}
22
3−module Idris.CaseSplit(split, splitOnLine, replaceSplits,
3+module Idris.CaseSplit(split, splitOnLine, replaceSplits,
44 getClause,
55 mkWith) where
66
@@ -30,9 +30,9 @@ import qualified Data.ByteString.UTF8 as UTF8
3030
3131import Debug.Trace
3232
33−{-
33+{-
3434
35−Given a pattern clause and a variable 'n', elaborate the cluse and find the
35+Given a pattern clause and a variable 'n', elaborate the clause and find the
3636type of 'n'.
3737
3838Make new pattern clauses by replacing 'n' with all the possibly constructors
@@ -47,7 +47,7 @@ names over '_', patterns over names, etc.
4747-- Given a variable to split, and a term application, return a list of
4848-- variable updates
4949split :: Name -> PTerm -> Idris [[(Name, PTerm)]]
50−split n t'
50+split n t'
5151 = do (tm, ty, pats) <- elabValBind toplevel True t'
5252 logLvl 4 ("Elaborated:\n" ++ show tm ++ " : " ++ show ty ++ "\n" ++ show pats)
5353 ist <- getIState
@@ -57,7 +57,7 @@ split n t'
5757 let ctxt = tt_ctxt ist
5858 case lookup n pats of
5959 Nothing -> fail $ show n ++ " is not a pattern variable"
60− Just ty ->
60+ Just ty ->
6161 do let splits = findPats ist ty
6262 iLOG ("New patterns " ++ show splits)
6363 let newPats_in = zipWith (replaceVar ctxt n) splits (repeat t)
@@ -65,7 +65,7 @@ split n t'
6565 logLvl 4 ("Trying " ++ showSep "\n" (map show newPats_in))
6666 newPats <- mapM elabNewPat newPats_in
6767 logLvl 3 ("Original:\n" ++ show t)
68− logLvl 3 ("Split:\n" ++
68+ logLvl 3 ("Split:\n" ++
6969 (showSep "\n" (map show (mapMaybe id newPats))))
7070 logLvl 3 "----"
7171 let newPats' = mergeAllPats ctxt t (mapMaybe id newPats)
@@ -75,17 +75,17 @@ split n t'
7575
7676data MergeState = MS { namemap :: [(Name, Name)],
7777 updates :: [(Name, PTerm)] }
78−
78+
7979addUpdate n tm = do ms <- get
8080 put (ms { updates = ((n, stripNS tm) : updates ms) } )
8181
82−stripNS tm = mapPT dens tm where
82+stripNS tm = mapPT dens tm where
8383 dens (PRef fc n) = PRef fc (nsroot n)
8484 dens t = t
8585
8686mergeAllPats :: Context -> PTerm -> [PTerm] -> [(PTerm, [(Name, PTerm)])]
8787mergeAllPats ctxt t [] = []
88−mergeAllPats ctxt t (p : ps)
88+mergeAllPats ctxt t (p : ps)
8989 = let (p', MS _ u) = runState (mergePat ctxt t p) (MS [] [])
9090 ps' = mergeAllPats ctxt t ps in
9191 ((p, u) : ps')
@@ -97,7 +97,7 @@ mergePat ctxt (PPatvar fc n) new
9797 = mergePat ctxt (PRef fc n) new
9898mergePat ctxt old (PPatvar fc n)
9999 = mergePat ctxt old (PRef fc n)
100−mergePat ctxt orig@(PRef fc n) new@(PRef _ n')
100+mergePat ctxt orig@(PRef fc n) new@(PRef _ n')
101101 | isDConName n' ctxt = do addUpdate n new;
102102 return new
103103 | otherwise
@@ -107,7 +107,7 @@ mergePat ctxt orig@(PRef fc n) new@(PRef _ n')
107107 return (PRef fc x)
108108 Nothing -> do put (ms { namemap = ((n', n) : namemap ms) })
109109 return (PRef fc n)
110−mergePat ctxt (PApp _ _ args) (PApp fc f args')
110+mergePat ctxt (PApp _ _ args) (PApp fc f args')
111111 = do newArgs <- zipWithM mergeArg args args'
112112 return (PApp fc f newArgs)
113113 where mergeArg x y = do tm' <- mergePat ctxt (getTm x) (getTm y)
@@ -124,7 +124,7 @@ mergePat ctxt x y = return y
124124mergeUserImpl :: PTerm -> PTerm -> PTerm
125125mergeUserImpl x y = x
126126
127−tidy orig@(PRef fc n)
127+tidy orig@(PRef fc n)
128128 = do ms <- get
129129 case lookup n (namemap ms) of
130130 Just x -> return (PRef fc x)
@@ -181,10 +181,10 @@ splitOnLine :: Int -- ^ line number
181181 -> Name -- ^ variable
182182 -> FilePath -- ^ name of file
183183 -> Idris [[(Name, PTerm)]]
184−splitOnLine l n fn = do
184+splitOnLine l n fn = do
185185-- let (before, later) = splitAt (l-1) (lines inp)
186186-- i <- getIState
187− cl <- getInternalApp fn l
187+ cl <- getInternalApp fn l
188188 logLvl 3 ("Working with " ++ showImp Nothing True False cl)
189189 tms <- split n cl
190190-- iputStrLn (showSep "\n" (map show tms))
@@ -210,7 +210,7 @@ replaceSplits l ups = updateRHSs 1 (map (rep (expandBraces l)) ups)
210210 return (x : xs', i')
211211 updateRHS i [] = return ("", i)
212212
213− getUniq nm i
213+ getUniq nm i
214214 = do ist <- getIState
215215 let n = nameRoot [] nm ++ "_" ++ show i
216216 case lookupTy (UN n) (tt_ctxt ist) of
@@ -218,15 +218,15 @@ replaceSplits l ups = updateRHSs 1 (map (rep (expandBraces l)) ups)
218218 _ -> getUniq nm (i+1)
219219
220220 nameRoot acc nm | all isDigit nm = showSep "_" acc
221− nameRoot acc nm =
221+ nameRoot acc nm =
222222 case span (/='_') nm of
223223 (before, ('_' : after)) -> nameRoot (acc ++ [before]) after
224224 _ -> showSep "_" (acc ++ [nm])
225225
226− -- TMP HACK: If there are Nats, we don't want to show as numerals since
226+ -- TMP HACK: If there are Nats, we don't want to show as numerals since
227227 -- this isn't supported in a pattern, so special case here
228228 nshow brack (PRef _ (UN "Z")) = "Z"
229− nshow brack (PApp _ (PRef _ (UN "S")) [x]) =
229+ nshow brack (PApp _ (PRef _ (UN "S")) [x]) =
230230 if brack then "(S " else "S " ++ nshow True (getTm x) ++
231231 if brack then ")" else ""
232232 nshow _ t = show t
@@ -235,14 +235,14 @@ replaceSplits l ups = updateRHSs 1 (map (rep (expandBraces l)) ups)
235235 expandBraces ('{' : xs)
236236 = let (brace, (_:rest)) = span (/= '}') xs in
237237 if (not ('=' `elem` brace))
238− then ('{' : brace ++ " = " ++ brace ++ "}") ++
238+ then ('{' : brace ++ " = " ++ brace ++ "}") ++
239239 expandBraces rest
240240 else ('{' : brace ++ "}") ++ expandBraces rest
241241 expandBraces (x : xs) = x : expandBraces xs
242242 expandBraces [] = []
243243
244244 updatePat start n tm [] = []
245− updatePat start n tm ('{':rest) =
245+ updatePat start n tm ('{':rest) =
246246 let (space, rest') = span isSpace rest in
247247 '{' : space ++ updatePat False n tm rest'
248248 updatePat True n tm xs@(c:rest) | length xs > length n
@@ -261,7 +261,7 @@ getClause :: Int -> -- ^ Line type is declared on
261261 Idris String
262262getClause l fn fp = do ty <- getInternalApp fp l
263263 let ap = mkApp ty [1..]
264− return (show fn ++ " " ++ ap ++
264+ return (show fn ++ " " ++ ap ++
265265 "= ?" ++ show fn ++ "_rhs")
266266 where mkApp (PPi (Exp _ _ _ False) (MN _ _) _ sc) (n : ns)
267267 = "x" ++ show n ++ " " ++ mkApp sc ns
@@ -275,17 +275,15 @@ getClause l fn fp = do ty <- getInternalApp fp l
275275
276276mkWith :: String -> Name -> String
277277mkWith str n = let ind = getIndent str
278− str' = replicate ind ' ' ++
278+ str' = replicate ind ' ' ++
279279 replaceRHS str "with (_)"
280− newpat = replicate (ind + 2) ' ' ++
280+ newpat = replicate (ind + 2) ' ' ++
281281 replaceRHS str "| with_pat = ?" ++ show n ++ "_rhs" in
282282 str' ++ "\n" ++ newpat
283−
283+
284284 where getIndent s = length (takeWhile isSpace s)
285285
286286 replaceRHS [] str = str
287287 replaceRHS ('?':'=': rest) str = str
288288 replaceRHS ('=': rest) str = str
289289 replaceRHS (x : rest) str = x : replaceRHS rest str
290−
291−