@@ -5,8 +5,9 @@ Copyright :
55License : BSD3
66Maintainer : The Idris Community.
77-}
8−{-# LANGUAGE DeriveFunctor, FlexibleInstances, MultiParamTypeClasses,
9− PatternGuards, TypeSynonymInstances #-}
8+
9+{-# LANGUAGE DeriveFunctor #-}
10+{-# LANGUAGE PatternGuards #-}
1011
1112module Idris.AbsSyntax(
1213 module Idris.AbsSyntax
@@ -15,37 +16,32 @@ module Idris.AbsSyntax(
1516
1617import Idris.AbsSyntaxTree
1718import Idris.Colours
18−import Idris.Core.Elaborate hiding (Tactic(..))
1919import Idris.Core.Evaluate
2020import Idris.Core.TT
21−import Idris.Core.Typecheck
2221import Idris.Docstrings
2322import Idris.IdeMode hiding (Opt(..))
2423import IRTS.CodegenCommon
2524
26−import Util.DynamicLinker
27−import Util.Pretty
28−import Util.ScreenSize
29−import Util.System
25+import System.Directory (canonicalizePath, doesFileExist)
26+import System.IO
3027
3128import Control.Applicative
32−import Control.Monad (liftM3)
3329import Control.Monad.State
34−import Data.Char
30+import Prelude hiding (Applicative, Foldable, Traversable, (<$>))
31+
3532import Data.Either
36−import Data.Generics.Uniplate.Data (descend, descendM)
3733import Data.List hiding (insert, union)
3834import qualified Data.Map as M
3935import Data.Maybe
4036import qualified Data.Set as S
4137import qualified Data.Text as T
42−import Data.Word (Word)
43−import Debug.Trace
44−import Network (PortID(PortNumber))
45−import System.Console.Haskeline
46−import System.Directory (canonicalizePath, doesFileExist)
47−import System.IO
48−import System.IO.Error (ioeGetErrorString, isUserError, tryIOError)
38+import System.IO.Error (tryIOError)
39+
40+import Data.Generics.Uniplate.Data (descend, descendM)
41+
42+import Util.DynamicLinker
43+import Util.Pretty
44+import Util.System
4945
5046getContext :: Idris Context
5147getContext = do i <- getIState; return (tt_ctxt i)
@@ -91,9 +87,9 @@ addDyLib libs = do i <- getIState
9187 Just x -> do putIState $ i { idris_dynamic_libs = x:ls }
9288 return (Left x)
9389 where findDyLib :: [DynamicLib] -> String -> Maybe DynamicLib
94− findDyLib [] l = Nothing
95− findDyLib (lib:libs) l | l == lib_name lib = Just lib
96− | otherwise = findDyLib libs l
90+ findDyLib [] _ = Nothing
91+ findDyLib (lib:libs') l | l == lib_name lib = Just lib
92+ | otherwise = findDyLib libs' l
9793
9894getAutoImports :: Idris [FilePath]
9995getAutoImports = do i <- getIState
@@ -102,7 +98,6 @@ getAutoImports = do i <- getIState
10298addAutoImport :: FilePath -> Idris ()
10399addAutoImport fp = do i <- getIState
104100 let opts = idris_options i
105− let autoimps = opt_autoImport opts
106101 put (i { idris_options = opts { opt_autoImport =
107102 fp : opt_autoImport opts } } )
108103
@@ -250,7 +245,7 @@ getCoercionsTo i ty =
250245 let cs = idris_coercions i
251246 (fn,_) = unApply (getRetTy ty) in
252247 findCoercions fn cs
253− where findCoercions t [] = []
248+ where findCoercions _ [] = []
254249 findCoercions t (n : ns) =
255250 let ps = case lookupTy n (tt_ctxt i) of
256251 [ty'] -> case unApply (getRetTy (normalise (tt_ctxt i) [] ty')) of
@@ -322,10 +317,10 @@ addTyInfConstraints fc ts = do logLvl 2 $ "TI missing: " ++ show ts
322317 do let (fx, _) = unApply x
323318 let (fy, _) = unApply y
324319 case (fx, fy) of
325− (P (TCon _ _) n _, P (TCon _ _) n' _) -> errWhen (n/=n)
320+ (P (TCon _ _) n _, P (TCon _ _) n' _) -> errWhen (n/=n) -- XXX: n' is unused. Should this be errWhen (n /= n')?
326321 (P (TCon _ _) n _, Constant _) -> errWhen True
327322 (Constant _, P (TCon _ _) n' _) -> errWhen True
328− (P (DCon _ _ _) n _, P (DCon _ _ _) n' _) -> errWhen (n/=n)
323+ (P (DCon _ _ _) n _, P (DCon _ _ _) n' _) -> errWhen (n/=n) -- XXX: n' is unused. Should this be errWhen (n /= n')?
329324 _ -> return ()
330325
331326 where errWhen True
@@ -353,12 +348,6 @@ addFunctionErrorHandlers f arg hs =
353348 -- will always be one of those two, thus no extra case
354349 putIState $ i { idris_function_errorhandlers = newHandlers }
355350
356−getFunctionErrorHandlers :: Name -> Name -> Idris [Name]
357−getFunctionErrorHandlers f arg = do i <- getIState
358− return . maybe [] S.toList $
359− undefined --lookup arg =<< lookupCtxtExact f (idris_function_errorhandlers i)
360−
361−
362351-- | Trace all the names in a call graph starting at the given name
363352getAllNames :: Name -> Idris [Name]
364353getAllNames n = do i <- getIState
@@ -414,7 +403,7 @@ addNameHint ty n
414403 putIState $ i { idris_namehints = addDef ty' ns' (idris_namehints i) }
415404
416405getNameHints :: IState -> Name -> [Name]
417−getNameHints i (UN arr) | arr == txt "->" = [sUN "f",sUN "g"]
406+getNameHints _ (UN arr) | arr == txt "->" = [sUN "f",sUN "g"]
418407getNameHints i n =
419408 case lookupCtxt n (idris_namehints i) of
420409 [ns] -> ns
@@ -430,7 +419,6 @@ getDeprecated n = do
430419 i <- getIState
431420 return $ lookupCtxtExact n (idris_deprecated i)
432421
433−
434422addFragile :: Name -> String -> Idris ()
435423addFragile n reason = do
436424 i <- getIState
@@ -442,15 +430,15 @@ getFragile n = do
442430 return $ lookupCtxtExact n (idris_fragile i)
443431
444432push_estack :: Name -> Bool -> Idris ()
445−push_estack n impl
433+push_estack n implementation
446434 = do i <- getIState
447− putIState (i { elab_stack = (n, impl) : elab_stack i })
435+ putIState (i { elab_stack = (n, implementation) : elab_stack i })
448436
449437pop_estack :: Idris ()
450438pop_estack = do i <- getIState
451439 putIState (i { elab_stack = ptail (elab_stack i) })
452440 where ptail [] = []
453− ptail (x : xs) = xs
441+ ptail (_ : xs) = xs
454442
455443-- | Add an interface implementation function.
456444--
@@ -546,7 +534,7 @@ addIBC ibc@(IBCDef n)
546534 when (notDef (ibc_write i)) $
547535 putIState $ i { ibc_write = ibc : ibc_write i }
548536 where notDef [] = True
549− notDef (IBCDef n': is) | n == n' = False
537+ notDef (IBCDef n': _) | n == n' = False
550538 notDef (_ : is) = notDef is
551539addIBC ibc = do i <- getIState; putIState $ i { ibc_write = ibc : ibc_write i }
552540
@@ -683,7 +671,7 @@ clearPTypes :: Idris ()
683671clearPTypes = do i <- get
684672 let ctxt = tt_ctxt i
685673 put (i { tt_ctxt = mapDefCtxt pErase ctxt })
686− where pErase (CaseOp c t tys orig tot cds)
674+ where pErase (CaseOp c t tys orig _ cds)
687675 = CaseOp c t tys orig [] (pErase' cds)
688676 pErase x = x
689677 pErase' (CaseDefs (cs, c) rs)
@@ -699,7 +687,7 @@ checkUndefined fc n
699687 _ -> return ()
700688
701689isUndefined :: FC -> Name -> Idris Bool
702−isUndefined fc n
690+isUndefined _ n
703691 = do i <- getContext
704692 case lookupTyExact n i of
705693 Just _ -> return False
@@ -756,7 +744,7 @@ addDeferred' nt ns
756744 tidyNames used (Bind n b sc)
757745 = let n' = uniqueNameSet n used in
758746 Bind n' b $ tidyNames (S.insert n' used) sc
759− tidyNames used b = b
747+ tidyNames _ b = b
760748
761749solveDeferred :: FC -> Name -> Idris ()
762750solveDeferred fc n
@@ -1144,7 +1132,6 @@ setColour ct c = do i <- getIState
11441132 setColour' PromptColour c t = t { promptColour = c }
11451133 setColour' PostulateColour c t = t { postulateColour = c }
11461134
1147−
11481135logLvl :: Int -> String -> Idris ()
11491136logLvl = logLvlCats []
11501137
@@ -1178,7 +1165,7 @@ logLvlCats :: [LogCat] -- ^ The categories that the message should appear under.
11781165 -> Int -- ^ The Logging level the message should appear.
11791166 -> String -- ^ The message to show the developer.
11801167 -> Idris ()
1181−logLvlCats cs l str = do
1168+logLvlCats cs l msg = do
11821169 i <- getIState
11831170 let lvl = opt_logLevel (idris_options i)
11841171 let cats = opt_logcats (idris_options i)
@@ -1186,9 +1173,9 @@ logLvlCats cs l str = do
11861173 when (inCat cs cats || null cats) $
11871174 case idris_outputmode i of
11881175 RawOutput h -> do
1189− runIO $ hPutStrLn h str
1176+ runIO $ hPutStrLn h msg
11901177 IdeMode n h -> do
1191− let good = SexpList [IntegerAtom (toInteger l), toSExp str]
1178+ let good = SexpList [IntegerAtom (toInteger l), toSExp msg]
11921179 runIO . hPutStrLn h $ convSExp "log" good n
11931180 where
11941181 inCat :: [LogCat] -> [LogCat] -> Bool
@@ -1210,6 +1197,29 @@ setTypeCase t = do i <- getIState
12101197 let opt' = opts { opt_typecase = t }
12111198 putIState $ i { idris_options = opt' }
12121199
1200+getIndentWith :: Idris Int
1201+getIndentWith = do
1202+ i <- getIState
1203+ return $ interactiveOpts_indentWith (idris_interactiveOpts i)
1204+
1205+setIndentWith :: Int -> Idris ()
1206+setIndentWith indentWith = do
1207+ i <- getIState
1208+ let opts = idris_interactiveOpts i
1209+ let opts' = opts { interactiveOpts_indentWith = indentWith }
1210+ putIState $ i { idris_interactiveOpts = opts' }
1211+
1212+getIndentClause :: Idris Int
1213+getIndentClause = do
1214+ i <- getIState
1215+ return $ interactiveOpts_indentClause (idris_interactiveOpts i)
1216+
1217+setIndentClause :: Int -> Idris ()
1218+setIndentClause indentClause = do
1219+ i <- getIState
1220+ let opts = idris_interactiveOpts i
1221+ let opts' = opts { interactiveOpts_indentClause = indentClause }
1222+ putIState $ i { idris_interactiveOpts = opts' }
12131223
12141224-- Dealing with parameters
12151225
@@ -2226,9 +2236,10 @@ instance Applicative (EitherErr a) where
22262236instance Monad (EitherErr a) where
22272237 return = RightOK
22282238
2229− (LeftErr e) >>= k = LeftErr e
2239+ (LeftErr e) >>= _ = LeftErr e
22302240 RightOK v >>= k = k v
22312241
2242+toEither :: EitherErr a b -> Either a b
22322243toEither (LeftErr e) = Left e
22332244toEither (RightOK ho) = Right ho
22342245
@@ -2439,7 +2450,7 @@ mkUniqueNames env shadows tm
24392450 -- looking for too long...)
24402451 initN (UN n) l = UN $ txt (str n ++ show l)
24412452 initN (MN i s) l = MN (i+l) s
2442− initN n l = n
2453+ initN n _ = n
24432454
24442455 -- FIXME: Probably ought to do this for completeness! It's fine as
24452456 -- long as there are no bindings inside tactics though.
@@ -2547,50 +2558,49 @@ mkUniqueNames env shadows tm
25472558
25482559 mkUniq ql nmap tm = descendM (mkUniq ql nmap) tm
25492560
2550−
25512561getFile :: Opt -> Maybe String
2552−getFile (Filename str) = Just str
2562+getFile (Filename s) = Just s
25532563getFile _ = Nothing
25542564
25552565getBC :: Opt -> Maybe String
2556−getBC (BCAsm str) = Just str
2566+getBC (BCAsm s) = Just s
25572567getBC _ = Nothing
25582568
25592569getOutput :: Opt -> Maybe String
2560−getOutput (Output str) = Just str
2570+getOutput (Output s) = Just s
25612571getOutput _ = Nothing
25622572
25632573getIBCSubDir :: Opt -> Maybe String
2564−getIBCSubDir (IBCSubDir str) = Just str
2574+getIBCSubDir (IBCSubDir s) = Just s
25652575getIBCSubDir _ = Nothing
25662576
25672577getImportDir :: Opt -> Maybe String
2568−getImportDir (ImportDir str) = Just str
2578+getImportDir (ImportDir s) = Just s
25692579getImportDir _ = Nothing
25702580
25712581getSourceDir :: Opt -> Maybe String
2572−getSourceDir (SourceDir str) = Just str
2582+getSourceDir (SourceDir s) = Just s
25732583getSourceDir _ = Nothing
25742584
25752585getPkgDir :: Opt -> Maybe String
2576−getPkgDir (Pkg str) = Just str
2586+getPkgDir (Pkg s) = Just s
25772587getPkgDir _ = Nothing
25782588
25792589getPkg :: Opt -> Maybe (Bool, String)
2580−getPkg (PkgBuild str) = Just (False, str)
2581−getPkg (PkgInstall str) = Just (True, str)
2590+getPkg (PkgBuild s) = Just (False, s)
2591+getPkg (PkgInstall s) = Just (True, s)
25822592getPkg _ = Nothing
25832593
25842594getPkgClean :: Opt -> Maybe String
2585−getPkgClean (PkgClean str) = Just str
2595+getPkgClean (PkgClean s) = Just s
25862596getPkgClean _ = Nothing
25872597
25882598getPkgREPL :: Opt -> Maybe String
2589−getPkgREPL (PkgREPL str) = Just str
2599+getPkgREPL (PkgREPL s) = Just s
25902600getPkgREPL _ = Nothing
25912601
25922602getPkgCheck :: Opt -> Maybe String
2593−getPkgCheck (PkgCheck str) = Just str
2603+getPkgCheck (PkgCheck s) = Just s
25942604getPkgCheck _ = Nothing
25952605
25962606-- | Returns None if given an Opt which is not PkgMkDoc
@@ -2618,7 +2628,6 @@ getConsoleWidth :: Opt -> Maybe ConsoleWidth
26182628getConsoleWidth (UseConsoleWidth x) = Just x
26192629getConsoleWidth _ = Nothing
26202630
2621−
26222631getExecScript :: Opt -> Maybe String
26232632getExecScript (InterpretScript expr) = Just expr
26242633getExecScript _ = Nothing
@@ -2667,7 +2676,7 @@ getClient _ = Nothing
26672676-- Get the first valid port
26682677getPort :: [Opt] -> Maybe REPLPort
26692678getPort [] = Nothing
2670−getPort (Port p : xs) = Just p
2679+getPort (Port p : _ ) = Just p
26712680getPort (_ : xs) = getPort xs
26722681
26732682opt :: (Opt -> Maybe a) -> [Opt] -> [a]