Skip to content

Commit 3a4f7e5

Browse files
committed
Drop a few dependencies
1 parent 48d0426 commit 3a4f7e5

11 files changed

Lines changed: 34 additions & 36 deletions

File tree

src/Options/Applicative/Builder/Extra.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ module Options.Applicative.Builder.Extra
3030
) where
3131

3232
import Control.Monad (when, forM)
33-
import Control.Monad.IO.Unlift
34-
import Data.Either.Combinators
3533
import Data.List (isPrefixOf)
3634
import Data.Maybe
3735
import Data.Monoid
@@ -40,6 +38,7 @@ import qualified Data.Text as T
4038
import Options.Applicative
4139
import Options.Applicative.Types (readerAsk)
4240
import Path hiding ((</>))
41+
import Stack.Prelude
4342
import System.Directory (getCurrentDirectory, getDirectoryContents, doesDirectoryExist)
4443
import System.Environment (withArgs)
4544
import System.FilePath (takeBaseName, (</>), splitFileName, isRelative, takeExtension)

src/Options/Applicative/Complicated.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Options.Applicative.Complicated
1313
) where
1414

1515
import Control.Monad.Trans.Class (lift)
16-
import Control.Monad.Trans.Either
16+
import Control.Monad.Trans.Except
1717
import Control.Monad.Trans.Writer
1818
import Data.Monoid
1919
import Data.Version
@@ -42,7 +42,7 @@ complicatedOptions
4242
-> Maybe (ParserFailure ParserHelp -> [String] -> IO (a,(b,a)))
4343
-- ^ optional handler for parser failure; 'handleParseResult' is called by
4444
-- default
45-
-> EitherT b (Writer (Mod CommandFields (b,a))) ()
45+
-> ExceptT b (Writer (Mod CommandFields (b,a))) ()
4646
-- ^ commands (use 'addCommand')
4747
-> IO (a,b)
4848
complicatedOptions numericVersion versionString numericHpackVersion h pd footerStr commonParser mOnFailure commandParser =
@@ -82,7 +82,7 @@ addCommand :: String -- ^ command string
8282
-> (a -> b) -- ^ constructor to wrap up command in common data type
8383
-> Parser c -- ^ common parser
8484
-> Parser a -- ^ command parser
85-
-> EitherT b (Writer (Mod CommandFields (b,c))) ()
85+
-> ExceptT b (Writer (Mod CommandFields (b,c))) ()
8686
addCommand cmd title footerStr constr =
8787
addCommand' cmd title footerStr (\a c -> (constr a,c))
8888

@@ -97,9 +97,9 @@ addSubCommands
9797
-- ^ footer of command help
9898
-> Parser c
9999
-- ^ common parser
100-
-> EitherT b (Writer (Mod CommandFields (b,c))) ()
100+
-> ExceptT b (Writer (Mod CommandFields (b,c))) ()
101101
-- ^ sub-commands (use 'addCommand')
102-
-> EitherT b (Writer (Mod CommandFields (b,c))) ()
102+
-> ExceptT b (Writer (Mod CommandFields (b,c))) ()
103103
addSubCommands cmd title footerStr commonParser commandParser =
104104
addCommand' cmd
105105
title
@@ -115,7 +115,7 @@ addCommand' :: String -- ^ command string
115115
-> (a -> c -> (b,c)) -- ^ constructor to wrap up command in common data type
116116
-> Parser c -- ^ common parser
117117
-> Parser a -- ^ command parser
118-
-> EitherT b (Writer (Mod CommandFields (b,c))) ()
118+
-> ExceptT b (Writer (Mod CommandFields (b,c))) ()
119119
addCommand' cmd title footerStr constr commonParser inner =
120120
lift (tell (command cmd
121121
(info (constr <$> inner <*> commonParser)
@@ -128,13 +128,13 @@ complicatedParser
128128
-- ^ metavar for the sub-command
129129
-> Parser a
130130
-- ^ common settings
131-
-> EitherT b (Writer (Mod CommandFields (b,a))) ()
131+
-> ExceptT b (Writer (Mod CommandFields (b,a))) ()
132132
-- ^ commands (use 'addCommand')
133133
-> Parser (a,(b,a))
134134
complicatedParser commandMetavar commonParser commandParser =
135135
(,) <$>
136136
commonParser <*>
137-
case runWriter (runEitherT commandParser) of
137+
case runWriter (runExceptT commandParser) of
138138
(Right (),d) -> hsubparser' commandMetavar d
139139
(Left b,_) -> pure (b,mempty)
140140

src/Stack/Options/ConfigParser.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Stack.Options.ConfigParser where
22

33
import Data.Char
4-
import Data.Either.Combinators
54
import Data.Monoid.Extra
65
import qualified Data.Set as Set
76
import Options.Applicative
@@ -14,6 +13,7 @@ import Stack.Options.GhcBuildParser
1413
import Stack.Options.GhcVariantParser
1514
import Stack.Options.NixParser
1615
import Stack.Options.Utils
16+
import Stack.Prelude
1717
import Stack.Types.Config
1818
import qualified System.FilePath as FilePath
1919

src/Stack/Package.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import Prelude.Compat
4646

4747
import Control.Arrow ((&&&))
4848
import Control.Monad (liftM, liftM2, (<=<), when, forM, forM_)
49-
import Control.Monad.IO.Unlift
5049
import Control.Monad.Logger
5150
import Control.Monad.Reader (MonadReader,runReaderT,ask,asks)
5251
import qualified Data.ByteString as BS
@@ -85,10 +84,10 @@ import Path as FL
8584
import Path.Extra
8685
import Path.Find
8786
import Path.IO hiding (findFiles)
88-
import Safe (headDef, tailSafe)
8987
import Stack.Build.Installed
9088
import Stack.Constants
9189
import Stack.Constants.Config
90+
import Stack.Prelude
9291
import Stack.PrettyPrint
9392
import Stack.Types.Build
9493
import Stack.Types.Compiler
@@ -1017,8 +1016,8 @@ parseDumpHI dumpHIPath = do
10171016
mapMaybe (D.simpleParse . T.unpack . decodeUtf8) $
10181017
C8.words $
10191018
C8.concat $
1020-
C8.dropWhile (/= ' ') (headDef "" startModuleDeps) :
1021-
takeWhile (" " `C8.isPrefixOf`) (tailSafe startModuleDeps)
1019+
C8.dropWhile (/= ' ') (fromMaybe "" $ listToMaybe startModuleDeps) :
1020+
takeWhile (" " `C8.isPrefixOf`) (drop 1 startModuleDeps)
10221021
thDeps =
10231022
-- The dependent file path is surrounded by quotes but is not escaped.
10241023
-- It can be an absolute or relative path.

src/Stack/Prelude.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Stack.Prelude
2+
( mapLeft
3+
, readMaybe
4+
, module Control.Monad.IO.Unlift
5+
) where
6+
7+
import Control.Monad.IO.Unlift
8+
import Text.Read (readMaybe)
9+
10+
mapLeft :: (a1 -> a2) -> Either a1 b -> Either a2 b
11+
mapLeft f (Left a1) = Left (f a1)
12+
mapLeft _ (Right b) = Right b

src/Stack/Setup.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import qualified Codec.Archive.Tar as Tar
3636
import Control.Applicative
3737
import Control.Concurrent.Async (Concurrently(..))
3838
import Control.Monad (liftM, when, join, unless, guard)
39-
import Control.Monad.IO.Unlift
4039
import Control.Monad.Logger
4140
import Control.Monad.Reader (MonadReader, ReaderT (..))
4241
import Control.Monad.State (get, put, modify)
@@ -84,14 +83,14 @@ import Path.Extra (toFilePathNoTrailingSep)
8483
import Path.IO hiding (findExecutable)
8584
import qualified Paths_stack as Meta
8685
import Prelude hiding (concat, elem, any) -- Fix AMP warning
87-
import Safe (headMay, readMay)
8886
import Stack.Build (build)
8987
import Stack.Config (loadConfig)
9088
import Stack.Constants (stackProgName)
9189
import Stack.Constants.Config (distRelativeDir)
9290
import Stack.Exec (defaultEnvSettings)
9391
import Stack.Fetch
9492
import Stack.GhcPkg (createDatabase, getCabalPkgVer, getGlobalDB, mkGhcPackagePath)
93+
import Stack.Prelude
9594
import Stack.PrettyPrint
9695
import Stack.Setup.Installed
9796
import Stack.Snapshot (loadSnapshot)
@@ -565,7 +564,7 @@ getGhcBuild menv = do
565564
eldconfigOut <- tryProcessStdout Nothing sbinEnv "ldconfig" ["-p"]
566565
egccErrOut <- tryProcessStderrStdout Nothing menv "gcc" ["-v"]
567566
let firstWords = case eldconfigOut of
568-
Right ldconfigOut -> mapMaybe (headMay . T.words) $
567+
Right ldconfigOut -> mapMaybe (listToMaybe . T.words) $
569568
T.lines $ T.decodeUtf8With T.lenientDecode ldconfigOut
570569
Left _ -> []
571570
checkLib lib
@@ -725,7 +724,7 @@ getSystemCompiler menv wc = do
725724
eres <- tryProcessStdout Nothing menv exeName ["--info"]
726725
let minfo = do
727726
Right bs <- Just eres
728-
pairs_ <- readMay $ S8.unpack bs :: Maybe [(String, String)]
727+
pairs_ <- readMaybe $ S8.unpack bs :: Maybe [(String, String)]
729728
version <- lookup "Project version" pairs_ >>= parseVersionFromString
730729
arch <- lookup "Target platform" pairs_ >>= simpleParse . takeWhile (/= '-')
731730
return (version, arch)

src/Stack/Types/Resolver.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ module Stack.Types.Resolver
3737

3838
import Control.Applicative
3939
import Control.DeepSeq (NFData)
40-
import Control.Monad.IO.Unlift
4140
import Data.Aeson.Extended
4241
(ToJSON, toJSON, FromJSON, parseJSON,
4342
withObject, (.:), withText)
@@ -61,7 +60,7 @@ import Options.Applicative (ReadM)
6160
import qualified Options.Applicative.Types as OA
6261
import Path
6362
import Prelude
64-
import Safe (readMay)
63+
import Stack.Prelude
6564
import Stack.Types.Compiler
6665
import qualified System.FilePath as FP
6766

@@ -211,7 +210,7 @@ parseSnapName t0 =
211210
return $ LTS x y
212211
nightly = do
213212
t1 <- T.stripPrefix "nightly-" t0
214-
Nightly <$> readMay (T.unpack t1)
213+
Nightly <$> readMaybe (T.unpack t1)
215214

216215
-- | Most recent Nightly and newest LTS version per major release.
217216
data Snapshots = Snapshots

src/Stack/Types/StackT.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ module Stack.Types.StackT
2727

2828
import Control.Applicative
2929
import Control.Monad
30-
import Control.Monad.Base
3130
import Control.Monad.IO.Unlift
3231
import Control.Monad.Logger
3332
import Control.Monad.Reader hiding (lift)
@@ -75,8 +74,6 @@ newtype StackT config m a =
7574
StackT {unStackT :: ReaderT (Env config) m a}
7675
deriving (Functor,Applicative,Monad,MonadIO,MonadReader (Env config),MonadThrow,MonadTrans)
7776

78-
deriving instance (MonadBase b m) => MonadBase b (StackT config m)
79-
8077
-- | Takes the configured log level into account.
8178
instance MonadIO m => MonadLogger (StackT config m) where
8279
monadLoggerLog = stickyLoggerFunc

src/Stack/Types/TemplateName.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
module Stack.Types.TemplateName where
99

10-
import Control.Error.Safe (justErr)
1110
import Control.Applicative
1211
import Data.Aeson.Extended (FromJSON, withText, parseJSON)
1312
import Data.Aeson.Types (typeMismatch)
@@ -80,7 +79,7 @@ parseTemplateNameFromString fname =
8079
Nothing -> parseValidFile (T.pack fname) (fname <> ".hsfiles") fname
8180
Just prefix -> parseValidFile prefix fname fname
8281
where
83-
parseValidFile prefix hsf orig = justErr expected
82+
parseValidFile prefix hsf orig = maybe (Left expected) Right
8483
$ asum (validParses prefix hsf orig)
8584
validParses prefix hsf orig =
8685
-- NOTE: order is important

src/main/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Control.Monad hiding (mapM, forM)
1919
import Control.Monad.IO.Unlift
2020
import Control.Monad.Logger
2121
import Control.Monad.Reader (local)
22-
import Control.Monad.Trans.Either (EitherT)
22+
import Control.Monad.Trans.Except (ExceptT)
2323
import Control.Monad.Writer.Lazy (Writer)
2424
import Data.Attoparsec.Args (parseArgs, EscapingMode (Escaping))
2525
import Data.Attoparsec.Interpreter (getInterpreterArgs)
@@ -471,7 +471,7 @@ commandLineHandler currentDir progName isInterpreter = complicatedOptions
471471
globalFooter = "Run 'stack --help' for global options that apply to all subcommands."
472472

473473
type AddCommand =
474-
EitherT (GlobalOpts -> IO ()) (Writer (Mod CommandFields (GlobalOpts -> IO (), GlobalOptsMonoid))) ()
474+
ExceptT (GlobalOpts -> IO ()) (Writer (Mod CommandFields (GlobalOpts -> IO (), GlobalOptsMonoid))) ()
475475

476476
-- | fall-through to external executables in `git` style if they exist
477477
-- (i.e. `stack something` looks for `stack-something` before

0 commit comments

Comments
 (0)