From df39a6d235dbe2a1debdb10589cda8774ecaedd5 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Wed, 29 Aug 2018 20:22:54 +1000 Subject: [PATCH] Add missing top-level type signatures Add `-Wmissing-signatures` to `ghc-options`. --- ihaskell.cabal | 6 ++--- main/IHaskellPrelude.hs | 36 +++++++++++++++++++-------- src/IHaskell/Display.hs | 1 + src/IHaskell/Eval/Completion.hs | 1 + src/IHaskell/Eval/Evaluate.hs | 1 + src/IHaskell/Eval/ParseShell.hs | 4 +++ src/IHaskell/Eval/Util.hs | 1 + src/IHaskell/Flags.hs | 3 +++ src/IHaskell/IPython.hs | 3 ++- src/IHaskellPrelude.hs | 30 ++++++++++++++++------ src/tests/IHaskell/Test/Completion.hs | 1 + 11 files changed, 65 insertions(+), 22 deletions(-) diff --git a/ihaskell.cabal b/ihaskell.cabal index b35810e0..059f8d2a 100644 --- a/ihaskell.cabal +++ b/ihaskell.cabal @@ -49,7 +49,7 @@ data-files: library hs-source-dirs: src default-language: Haskell2010 - ghc-options: -Wincomplete-patterns + ghc-options: -Wincomplete-patterns -Wmissing-signatures build-depends: aeson >=1.0, base >=4.9, @@ -125,7 +125,7 @@ executable ihaskell -- Other library packages from which modules are imported. default-language: Haskell2010 - ghc-options: -Wincomplete-patterns + ghc-options: -Wincomplete-patterns -Wmissing-signatures build-depends: ihaskell -any, base >=4.9 && < 4.13, @@ -152,7 +152,7 @@ Test-Suite hspec IHaskell.Test.Util IHaskell.Test.Parser default-language: Haskell2010 - ghc-options: -Wincomplete-patterns + ghc-options: -Wincomplete-patterns -Wmissing-signatures build-depends: base, ihaskell, diff --git a/main/IHaskellPrelude.hs b/main/IHaskellPrelude.hs index 271d7439..8a6bab31 100644 --- a/main/IHaskellPrelude.hs +++ b/main/IHaskellPrelude.hs @@ -1,4 +1,5 @@ -{-# language NoImplicitPrelude, DoAndIfThenElse, OverloadedStrings, ExtendedDefaultRules #-}{-# LANGUAGE CPP #-} +{-# language NoImplicitPrelude, DoAndIfThenElse, OverloadedStrings, ExtendedDefaultRules #-} +{-# LANGUAGE CPP #-} module IHaskellPrelude ( module IHaskellPrelude, module X, @@ -64,7 +65,8 @@ module IHaskellPrelude ( import Prelude -import Data.Monoid as X +import Data.Semigroup as X +import Data.Monoid as X hiding ((<>), First(..), Last(..)) import Data.Tuple as X import Control.Monad as X import Data.Maybe as X @@ -83,7 +85,7 @@ import Data.List as X hiding (head, last, tail, init, tra elemIndices, elemIndex, findIndex, findIndices, zip5, zip6, zip7, zipWith5, zipWith6, zipWith7, unzip5, unzip6, unzip6, delete, union, lookup, intersect, insert, deleteBy, - deleteFirstBy, unionBy, intersectBy, group, groupBy, insertBy, + unionBy, intersectBy, group, groupBy, insertBy, maximumBy, minimumBy, genericLength, genericDrop, genericTake, genericSplitAt, genericIndex, genericReplicate, inits, tails) @@ -111,13 +113,27 @@ type LByteString = Data.ByteString.Lazy.ByteString type LText = Data.Text.Lazy.Text -(headMay, tailMay, lastMay, initMay, maximumMay, minimumMay) = - (wrapEmpty head, wrapEmpty tail, wrapEmpty last, - wrapEmpty init, wrapEmpty maximum, wrapEmpty minimum) - where - wrapEmpty :: ([a] -> b) -> [a] -> Maybe b - wrapEmpty _ [] = Nothing - wrapEmpty f xs = Just (f xs) +headMay :: [a] -> Maybe a +headMay = wrapEmpty head + +tailMay :: [a] -> Maybe [a] +tailMay = wrapEmpty tail + +lastMay :: [a] -> Maybe a +lastMay = wrapEmpty last + +initMay :: [a] -> Maybe [a] +initMay = wrapEmpty init + +maximumMay :: Ord a => [a] -> Maybe a +maximumMay = wrapEmpty maximum + +minimumMay :: Ord a => [a] -> Maybe a +minimumMay = wrapEmpty minimum + +wrapEmpty :: ([a] -> b) -> [a] -> Maybe b +wrapEmpty _ [] = Nothing +wrapEmpty f xs = Just (f xs) maximumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a maximumByMay _ [] = Nothing diff --git a/src/IHaskell/Display.hs b/src/IHaskell/Display.hs index 1df19ac8..2e099097 100644 --- a/src/IHaskell/Display.hs +++ b/src/IHaskell/Display.hs @@ -201,6 +201,7 @@ printDisplay disp = display disp >>= atomically . writeTChan displayChan -- | Convenience function for client libraries. Switch to a temporary directory so that any files we -- create aren't visible. On Unix, this is usually /tmp. +switchToTmpDir :: IO () switchToTmpDir = void (try switchDir :: IO (Either SomeException ())) where switchDir = diff --git a/src/IHaskell/Eval/Completion.hs b/src/IHaskell/Eval/Completion.hs index bae09217..8863c24a 100644 --- a/src/IHaskell/Eval/Completion.hs +++ b/src/IHaskell/Eval/Completion.hs @@ -69,6 +69,7 @@ exposedName :: (a, b) -> a exposedName = fst #endif +extName (FlagSpec { flagSpecName = name }) = name extName (FlagSpec { flagSpecName = name }) = name complete :: String -> Int -> Interpreter (String, [String]) diff --git a/src/IHaskell/Eval/Evaluate.hs b/src/IHaskell/Eval/Evaluate.hs index 8760f60b..986e1746 100644 --- a/src/IHaskell/Eval/Evaluate.hs +++ b/src/IHaskell/Eval/Evaluate.hs @@ -1110,6 +1110,7 @@ doLoadModule name modName = do return $ displayError $ "Failed to load module " ++ modName ++ ": " ++ show exception +objTarget :: DynFlags -> HscTarget objTarget flags = defaultObjectTarget $ targetPlatform flags keepingItVariable :: Interpreter a -> Interpreter a diff --git a/src/IHaskell/Eval/ParseShell.hs b/src/IHaskell/Eval/ParseShell.hs index c8d723eb..d514234f 100644 --- a/src/IHaskell/Eval/ParseShell.hs +++ b/src/IHaskell/Eval/ParseShell.hs @@ -28,6 +28,7 @@ manyTillEnd p end = scan xs <- scan return $ x : xs +manyTillEnd1 :: Parser a -> Parser [a] -> Parser [a] manyTillEnd1 p end = do x <- p xs <- manyTillEnd p end @@ -39,15 +40,18 @@ unescapedChar p = try $ do lookAhead p return [x] +quotedString :: Parser [Char] quotedString = do quote "expected starting quote" (manyTillEnd anyChar (unescapedChar quote) <* quote) "unexpected in quoted String " +unquotedString :: Parser [Char] unquotedString = manyTillEnd1 anyChar end where end = unescapedChar space <|> (lookAhead eol >> return []) +word :: Parser [Char] word = quotedString <|> unquotedString "word" separator :: Parser String diff --git a/src/IHaskell/Eval/Util.hs b/src/IHaskell/Eval/Util.hs index 1ff8ab07..d48b5f21 100644 --- a/src/IHaskell/Eval/Util.hs +++ b/src/IHaskell/Eval/Util.hs @@ -139,6 +139,7 @@ pprDynFlags show_all dflags = flgs1 = [Opt_PrintExplicitForalls] flgs2 = [Opt_PrintExplicitKinds] +flgs3 :: [GeneralFlag] flgs3 = [Opt_PrintBindResult, Opt_BreakOnException, Opt_BreakOnError, Opt_PrintEvldWithShow] -- | Pretty-print the base language and active options (taken from `InteractiveUI` module of diff --git a/src/IHaskell/Flags.hs b/src/IHaskell/Flags.hs index 751554f8..57f80bb6 100644 --- a/src/IHaskell/Flags.hs +++ b/src/IHaskell/Flags.hs @@ -132,8 +132,10 @@ installPrefixFlag :: Flag Args installPrefixFlag = flagReq ["prefix"] (store KernelspecInstallPrefix) "" "Installation prefix for kernelspec (see Jupyter's --prefix option)" +helpFlag :: Flag Args helpFlag = flagHelpSimple (add Help) +add :: Argument -> Args -> Args add flag (Args mode flags) = Args mode $ flag : flags store :: (String -> Argument) -> String -> Args -> Either String Args @@ -204,6 +206,7 @@ ihaskellArgs = where add flag (Args mode flags) = Args mode $ flag : flags +noArgs :: Arg a noArgs = flagArg unexpected "" where unexpected a = error $ "Unexpected argument: " ++ a diff --git a/src/IHaskell/IPython.hs b/src/IHaskell/IPython.hs index 7ff1443d..0ea9a324 100644 --- a/src/IHaskell/IPython.hs +++ b/src/IHaskell/IPython.hs @@ -106,6 +106,7 @@ ipython suppress args = do else return "" -- | Run while suppressing all output. +quietRun :: SH.FilePath -> [Text] -> SH.Sh () quietRun path args = SH.runHandles path args handles nothing where handles = [SH.InHandle SH.Inherit, SH.OutHandle SH.CreatePipe, SH.ErrorHandle SH.CreatePipe] @@ -267,7 +268,7 @@ getIHaskellPath = do -- If we have an absolute path, that's the IHaskell we're interested in. if FP.isAbsolute f then return f - else + else -- Check whether this is a relative path, or just 'IHaskell' with $PATH resolution done by -- the shell. If it's just 'IHaskell', use the $PATH variable to find where IHaskell lives. if FP.takeFileName f == f diff --git a/src/IHaskellPrelude.hs b/src/IHaskellPrelude.hs index e0d98307..8a6bab31 100644 --- a/src/IHaskellPrelude.hs +++ b/src/IHaskellPrelude.hs @@ -85,7 +85,7 @@ import Data.List as X hiding (head, last, tail, init, tra elemIndices, elemIndex, findIndex, findIndices, zip5, zip6, zip7, zipWith5, zipWith6, zipWith7, unzip5, unzip6, unzip6, delete, union, lookup, intersect, insert, deleteBy, - deleteFirstBy, unionBy, intersectBy, group, groupBy, insertBy, + unionBy, intersectBy, group, groupBy, insertBy, maximumBy, minimumBy, genericLength, genericDrop, genericTake, genericSplitAt, genericIndex, genericReplicate, inits, tails) @@ -113,13 +113,27 @@ type LByteString = Data.ByteString.Lazy.ByteString type LText = Data.Text.Lazy.Text -(headMay, tailMay, lastMay, initMay, maximumMay, minimumMay) = - (wrapEmpty head, wrapEmpty tail, wrapEmpty last, - wrapEmpty init, wrapEmpty maximum, wrapEmpty minimum) - where - wrapEmpty :: ([a] -> b) -> [a] -> Maybe b - wrapEmpty _ [] = Nothing - wrapEmpty f xs = Just (f xs) +headMay :: [a] -> Maybe a +headMay = wrapEmpty head + +tailMay :: [a] -> Maybe [a] +tailMay = wrapEmpty tail + +lastMay :: [a] -> Maybe a +lastMay = wrapEmpty last + +initMay :: [a] -> Maybe [a] +initMay = wrapEmpty init + +maximumMay :: Ord a => [a] -> Maybe a +maximumMay = wrapEmpty maximum + +minimumMay :: Ord a => [a] -> Maybe a +minimumMay = wrapEmpty minimum + +wrapEmpty :: ([a] -> b) -> [a] -> Maybe b +wrapEmpty _ [] = Nothing +wrapEmpty f xs = Just (f xs) maximumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a maximumByMay _ [] = Nothing diff --git a/src/tests/IHaskell/Test/Completion.hs b/src/tests/IHaskell/Test/Completion.hs index c8a42998..f28c2fdb 100644 --- a/src/tests/IHaskell/Test/Completion.hs +++ b/src/tests/IHaskell/Test/Completion.hs @@ -48,6 +48,7 @@ shouldHaveCompletionsInDirectory string expected = do unmatched = filter (not . existsInCompletion) expected expected `shouldBeAmong` completions +completionHas :: String -> [String] -> IO () completionHas string expected = do (matched, completions) <- ghc $ do initCompleter