@@ -5,8 +5,8 @@ Copyright :
55License : BSD3
66Maintainer : The Idris Community.
77-}
8−{-# LANGUAGE DeriveFunctor, FlexibleInstances, MultiParamTypeClasses,
9− PatternGuards, TypeSynonymInstances #-}
8+
9+{-# LANGUAGE DeriveFunctor, PatternGuards #-}
1010
1111module Idris.AbsSyntax(
1212 module Idris.AbsSyntax
@@ -15,37 +15,32 @@ module Idris.AbsSyntax(
1515
1616import Idris.AbsSyntaxTree
1717import Idris.Colours
18−import Idris.Core.Elaborate hiding (Tactic(..))
1918import Idris.Core.Evaluate
2019import Idris.Core.TT
21−import Idris.Core.Typecheck
2220import Idris.Docstrings
2321import Idris.IdeMode hiding (Opt(..))
2422import IRTS.CodegenCommon
2523
26−import Util.DynamicLinker
27−import Util.Pretty
28−import Util.ScreenSize
29−import Util.System
24+import System.Directory (canonicalizePath, doesFileExist)
25+import System.IO
3026
3127import Control.Applicative
32−import Control.Monad (liftM3)
3328import Control.Monad.State
34−import Data.Char
29+import Prelude hiding (Applicative, Foldable, Traversable, (<$>))
30+
3531import Data.Either
36−import Data.Generics.Uniplate.Data (descend, descendM)
3732import Data.List hiding (insert, union)
3833import qualified Data.Map as M
3934import Data.Maybe
4035import qualified Data.Set as S
4136import 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)
37+import System.IO.Error (tryIOError)
38+
39+import Data.Generics.Uniplate.Data (descend, descendM)
40+
41+import Util.DynamicLinker
42+import Util.Pretty
43+import Util.System
4944
5045getContext :: Idris Context
5146getContext = do i <- getIState; return (tt_ctxt i)
@@ -91,9 +86,9 @@ addDyLib libs = do i <- getIState
9186 Just x -> do putIState $ i { idris_dynamic_libs = x:ls }
9287 return (Left x)
9388 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
89+ findDyLib [] _ = Nothing
90+ findDyLib (lib:libs') l | l == lib_name lib = Just lib
91+ | otherwise = findDyLib libs' l
9792
9893getAutoImports :: Idris [FilePath]
9994getAutoImports = do i <- getIState
@@ -102,7 +97,6 @@ getAutoImports = do i <- getIState
10297addAutoImport :: FilePath -> Idris ()
10398addAutoImport fp = do i <- getIState
10499 let opts = idris_options i
105− let autoimps = opt_autoImport opts
106100 put (i { idris_options = opts { opt_autoImport =
107101 fp : opt_autoImport opts } } )
108102
@@ -250,7 +244,7 @@ getCoercionsTo i ty =
250244 let cs = idris_coercions i
251245 (fn,_) = unApply (getRetTy ty) in
252246 findCoercions fn cs
253− where findCoercions t [] = []
247+ where findCoercions _ [] = []
254248 findCoercions t (n : ns) =
255249 let ps = case lookupTy n (tt_ctxt i) of
256250 [ty'] -> case unApply (getRetTy (normalise (tt_ctxt i) [] ty')) of
@@ -322,10 +316,10 @@ addTyInfConstraints fc ts = do logLvl 2 $ "TI missing: " ++ show ts
322316 do let (fx, _) = unApply x
323317 let (fy, _) = unApply y
324318 case (fx, fy) of
325− (P (TCon _ _) n _, P (TCon _ _) n' _) -> errWhen (n/=n)
319+ (P (TCon _ _) n _, P (TCon _ _) n' _) -> errWhen (n/=n) -- XXX: n' is unused. Should this be errWhen (n /= n')?
326320 (P (TCon _ _) n _, Constant _) -> errWhen True
327321 (Constant _, P (TCon _ _) n' _) -> errWhen True
328− (P (DCon _ _ _) n _, P (DCon _ _ _) n' _) -> errWhen (n/=n)
322+ (P (DCon _ _ _) n _, P (DCon _ _ _) n' _) -> errWhen (n/=n) -- XXX: n' is unused. Should this be errWhen (n /= n')?
329323 _ -> return ()
330324
331325 where errWhen True
@@ -353,12 +347,6 @@ addFunctionErrorHandlers f arg hs =
353347 -- will always be one of those two, thus no extra case
354348 putIState $ i { idris_function_errorhandlers = newHandlers }
355349
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−
362350-- | Trace all the names in a call graph starting at the given name
363351getAllNames :: Name -> Idris [Name]
364352getAllNames n = do i <- getIState
@@ -414,7 +402,7 @@ addNameHint ty n
414402 putIState $ i { idris_namehints = addDef ty' ns' (idris_namehints i) }
415403
416404getNameHints :: IState -> Name -> [Name]
417−getNameHints i (UN arr) | arr == txt "->" = [sUN "f",sUN "g"]
405+getNameHints _ (UN arr) | arr == txt "->" = [sUN "f",sUN "g"]
418406getNameHints i n =
419407 case lookupCtxt n (idris_namehints i) of
420408 [ns] -> ns
@@ -430,7 +418,6 @@ getDeprecated n = do
430418 i <- getIState
431419 return $ lookupCtxtExact n (idris_deprecated i)
432420
433−
434421addFragile :: Name -> String -> Idris ()
435422addFragile n reason = do
436423 i <- getIState
@@ -442,15 +429,15 @@ getFragile n = do
442429 return $ lookupCtxtExact n (idris_fragile i)
443430
444431push_estack :: Name -> Bool -> Idris ()
445−push_estack n impl
432+push_estack n implementation
446433 = do i <- getIState
447− putIState (i { elab_stack = (n, impl) : elab_stack i })
434+ putIState (i { elab_stack = (n, implementation) : elab_stack i })
448435
449436pop_estack :: Idris ()
450437pop_estack = do i <- getIState
451438 putIState (i { elab_stack = ptail (elab_stack i) })
452439 where ptail [] = []
453− ptail (x : xs) = xs
440+ ptail (_ : xs) = xs
454441
455442-- | Add an interface implementation function.
456443--
@@ -546,7 +533,7 @@ addIBC ibc@(IBCDef n)
546533 when (notDef (ibc_write i)) $
547534 putIState $ i { ibc_write = ibc : ibc_write i }
548535 where notDef [] = True
549− notDef (IBCDef n': is) | n == n' = False
536+ notDef (IBCDef n': _) | n == n' = False
550537 notDef (_ : is) = notDef is
551538addIBC ibc = do i <- getIState; putIState $ i { ibc_write = ibc : ibc_write i }
552539
@@ -683,7 +670,7 @@ clearPTypes :: Idris ()
683670clearPTypes = do i <- get
684671 let ctxt = tt_ctxt i
685672 put (i { tt_ctxt = mapDefCtxt pErase ctxt })
686− where pErase (CaseOp c t tys orig tot cds)
673+ where pErase (CaseOp c t tys orig _ cds)
687674 = CaseOp c t tys orig [] (pErase' cds)
688675 pErase x = x
689676 pErase' (CaseDefs (cs, c) rs)
@@ -699,7 +686,7 @@ checkUndefined fc n
699686 _ -> return ()
700687
701688isUndefined :: FC -> Name -> Idris Bool
702−isUndefined fc n
689+isUndefined _ n
703690 = do i <- getContext
704691 case lookupTyExact n i of
705692 Just _ -> return False
@@ -756,7 +743,7 @@ addDeferred' nt ns
756743 tidyNames used (Bind n b sc)
757744 = let n' = uniqueNameSet n used in
758745 Bind n' b $ tidyNames (S.insert n' used) sc
759− tidyNames used b = b
746+ tidyNames _ b = b
760747
761748solveDeferred :: FC -> Name -> Idris ()
762749solveDeferred fc n
@@ -1144,7 +1131,6 @@ setColour ct c = do i <- getIState
11441131 setColour' PromptColour c t = t { promptColour = c }
11451132 setColour' PostulateColour c t = t { postulateColour = c }
11461133
1147−
11481134logLvl :: Int -> String -> Idris ()
11491135logLvl = logLvlCats []
11501136
@@ -1178,7 +1164,7 @@ logLvlCats :: [LogCat] -- ^ The categories that the message should appear under.
11781164 -> Int -- ^ The Logging level the message should appear.
11791165 -> String -- ^ The message to show the developer.
11801166 -> Idris ()
1181−logLvlCats cs l str = do
1167+logLvlCats cs l msg = do
11821168 i <- getIState
11831169 let lvl = opt_logLevel (idris_options i)
11841170 let cats = opt_logcats (idris_options i)
@@ -1186,9 +1172,9 @@ logLvlCats cs l str = do
11861172 when (inCat cs cats || null cats) $
11871173 case idris_outputmode i of
11881174 RawOutput h -> do
1189− runIO $ hPutStrLn h str
1175+ runIO $ hPutStrLn h msg
11901176 IdeMode n h -> do
1191− let good = SexpList [IntegerAtom (toInteger l), toSExp str]
1177+ let good = SexpList [IntegerAtom (toInteger l), toSExp msg]
11921178 runIO . hPutStrLn h $ convSExp "log" good n
11931179 where
11941180 inCat :: [LogCat] -> [LogCat] -> Bool
@@ -1210,6 +1196,29 @@ setTypeCase t = do i <- getIState
12101196 let opt' = opts { opt_typecase = t }
12111197 putIState $ i { idris_options = opt' }
12121198
1199+getIndentWith :: Idris Int
1200+getIndentWith = do
1201+ i <- getIState
1202+ return $ interactiveOpts_indentWith (idris_interactiveOpts i)
1203+
1204+setIndentWith :: Int -> Idris ()
1205+setIndentWith indentWith = do
1206+ i <- getIState
1207+ let opts = idris_interactiveOpts i
1208+ let opts' = opts { interactiveOpts_indentWith = indentWith }
1209+ putIState $ i { idris_interactiveOpts = opts' }
1210+
1211+getIndentClause :: Idris Int
1212+getIndentClause = do
1213+ i <- getIState
1214+ return $ interactiveOpts_indentClause (idris_interactiveOpts i)
1215+
1216+setIndentClause :: Int -> Idris ()
1217+setIndentClause indentClause = do
1218+ i <- getIState
1219+ let opts = idris_interactiveOpts i
1220+ let opts' = opts { interactiveOpts_indentClause = indentClause }
1221+ putIState $ i { idris_interactiveOpts = opts' }
12131222
12141223-- Dealing with parameters
12151224
@@ -2226,9 +2235,10 @@ instance Applicative (EitherErr a) where
22262235instance Monad (EitherErr a) where
22272236 return = RightOK
22282237
2229− (LeftErr e) >>= k = LeftErr e
2238+ (LeftErr e) >>= _ = LeftErr e
22302239 RightOK v >>= k = k v
22312240
2241+toEither :: EitherErr a b -> Either a b
22322242toEither (LeftErr e) = Left e
22332243toEither (RightOK ho) = Right ho
22342244
@@ -2439,7 +2449,7 @@ mkUniqueNames env shadows tm
24392449 -- looking for too long...)
24402450 initN (UN n) l = UN $ txt (str n ++ show l)
24412451 initN (MN i s) l = MN (i+l) s
2442− initN n l = n
2452+ initN n _ = n
24432453
24442454 -- FIXME: Probably ought to do this for completeness! It's fine as
24452455 -- long as there are no bindings inside tactics though.
@@ -2547,50 +2557,49 @@ mkUniqueNames env shadows tm
25472557
25482558 mkUniq ql nmap tm = descendM (mkUniq ql nmap) tm
25492559
2550−
25512560getFile :: Opt -> Maybe String
2552−getFile (Filename str) = Just str
2561+getFile (Filename s) = Just s
25532562getFile _ = Nothing
25542563
25552564getBC :: Opt -> Maybe String
2556−getBC (BCAsm str) = Just str
2565+getBC (BCAsm s) = Just s
25572566getBC _ = Nothing
25582567
25592568getOutput :: Opt -> Maybe String
2560−getOutput (Output str) = Just str
2569+getOutput (Output s) = Just s
25612570getOutput _ = Nothing
25622571
25632572getIBCSubDir :: Opt -> Maybe String
2564−getIBCSubDir (IBCSubDir str) = Just str
2573+getIBCSubDir (IBCSubDir s) = Just s
25652574getIBCSubDir _ = Nothing
25662575
25672576getImportDir :: Opt -> Maybe String
2568−getImportDir (ImportDir str) = Just str
2577+getImportDir (ImportDir s) = Just s
25692578getImportDir _ = Nothing
25702579
25712580getSourceDir :: Opt -> Maybe String
2572−getSourceDir (SourceDir str) = Just str
2581+getSourceDir (SourceDir s) = Just s
25732582getSourceDir _ = Nothing
25742583
25752584getPkgDir :: Opt -> Maybe String
2576−getPkgDir (Pkg str) = Just str
2585+getPkgDir (Pkg s) = Just s
25772586getPkgDir _ = Nothing
25782587
25792588getPkg :: Opt -> Maybe (Bool, String)
2580−getPkg (PkgBuild str) = Just (False, str)
2581−getPkg (PkgInstall str) = Just (True, str)
2589+getPkg (PkgBuild s) = Just (False, s)
2590+getPkg (PkgInstall s) = Just (True, s)
25822591getPkg _ = Nothing
25832592
25842593getPkgClean :: Opt -> Maybe String
2585−getPkgClean (PkgClean str) = Just str
2594+getPkgClean (PkgClean s) = Just s
25862595getPkgClean _ = Nothing
25872596
25882597getPkgREPL :: Opt -> Maybe String
2589−getPkgREPL (PkgREPL str) = Just str
2598+getPkgREPL (PkgREPL s) = Just s
25902599getPkgREPL _ = Nothing
25912600
25922601getPkgCheck :: Opt -> Maybe String
2593−getPkgCheck (PkgCheck str) = Just str
2602+getPkgCheck (PkgCheck s) = Just s
25942603getPkgCheck _ = Nothing
25952604
25962605-- | Returns None if given an Opt which is not PkgMkDoc
@@ -2618,7 +2627,6 @@ getConsoleWidth :: Opt -> Maybe ConsoleWidth
26182627getConsoleWidth (UseConsoleWidth x) = Just x
26192628getConsoleWidth _ = Nothing
26202629
2621−
26222630getExecScript :: Opt -> Maybe String
26232631getExecScript (InterpretScript expr) = Just expr
26242632getExecScript _ = Nothing
@@ -2667,7 +2675,7 @@ getClient _ = Nothing
26672675-- Get the first valid port
26682676getPort :: [Opt] -> Maybe REPLPort
26692677getPort [] = Nothing
2670−getPort (Port p : xs) = Just p
2678+getPort (Port p : _ ) = Just p
26712679getPort (_ : xs) = getPort xs
26722680
26732681opt :: (Opt -> Maybe a) -> [Opt] -> [a]