Eliminate MonadIO from MonadEffects instance for Lazy
This commit is contained in:
parent
c655bdb9f2
commit
e6b189e69b
|
@ -32,7 +32,6 @@ import Control.Applicative
|
|||
import Control.Monad
|
||||
import Control.Monad.Catch hiding (catchJust)
|
||||
import Control.Monad.Fix
|
||||
import Control.Monad.IO.Class
|
||||
import Control.Monad.Reader
|
||||
import Control.Monad.Ref
|
||||
import Control.Monad.State.Strict
|
||||
|
@ -511,7 +510,7 @@ instance MonadIntrospect m => MonadIntrospect (Lazy m)
|
|||
|
||||
instance (MonadFix m, MonadCatch m, MonadFile m, MonadStore m, MonadVar m,
|
||||
MonadPutStr m, MonadHttp m, MonadEnv m, MonadInstantiate m, MonadExec m,
|
||||
MonadIntrospect m, MonadIO m, Alternative m, MonadPlus m, Typeable m)
|
||||
MonadIntrospect m, Alternative m, MonadPlus m, Typeable m)
|
||||
=> MonadEffects (Lazy m) where
|
||||
makeAbsolutePath origPath = do
|
||||
origPathExpanded <- expandHomePath origPath
|
||||
|
@ -542,7 +541,7 @@ instance (MonadFix m, MonadCatch m, MonadFile m, MonadStore m, MonadVar m,
|
|||
evalExprLoc =<< case M.lookup path imports of
|
||||
Just expr -> pure expr
|
||||
Nothing -> do
|
||||
eres <- Lazy $ parseNixFileLoc path
|
||||
eres <- parseNixFileLoc path
|
||||
case eres of
|
||||
Failure err ->
|
||||
throwError $ ErrorCall . show $
|
||||
|
@ -612,7 +611,7 @@ x <///> y | isAbsolute y || "." `isPrefixOf` y = x </> y
|
|||
joinPath $ head [ xs ++ drop (length tx) ys
|
||||
| tx <- tails xs, tx `elem` inits ys ]
|
||||
|
||||
findPathBy :: forall e m. (MonadNix e m, MonadIO m) =>
|
||||
findPathBy :: forall e m. MonadNix e m =>
|
||||
(FilePath -> m (Maybe FilePath)) ->
|
||||
[NThunk m] -> FilePath -> m FilePath
|
||||
findPathBy finder l name = do
|
||||
|
@ -649,17 +648,17 @@ findPathBy finder l name = do
|
|||
throwError $ ErrorCall $ "__nixPath must be a list of attr sets"
|
||||
++ " with 'path' elements, but saw: " ++ show s
|
||||
|
||||
findPathM :: forall e m. (MonadNix e m, MonadIO m) =>
|
||||
findPathM :: forall e m. MonadNix e m =>
|
||||
[NThunk m] -> FilePath -> m FilePath
|
||||
findPathM l name = findPathBy path l name
|
||||
where
|
||||
path :: (MonadEffects m, MonadIO m) => FilePath -> m (Maybe FilePath)
|
||||
path :: MonadEffects m => FilePath -> m (Maybe FilePath)
|
||||
path path = do
|
||||
path <- makeAbsolutePath path
|
||||
exists <- doesPathExist path
|
||||
return $ if exists then Just path else Nothing
|
||||
|
||||
findEnvPathM :: forall e m. (MonadNix e m, MonadIO m)
|
||||
findEnvPathM :: forall e m. MonadNix e m
|
||||
=> FilePath -> m FilePath
|
||||
findEnvPathM name = do
|
||||
mres <- lookupVar @_ @(NThunk m) "__nixPath"
|
||||
|
@ -668,7 +667,7 @@ findEnvPathM name = do
|
|||
Just x -> force x $ fromValue >=> \(l :: [NThunk m]) ->
|
||||
findPathBy nixFilePath l name
|
||||
where
|
||||
nixFilePath :: (MonadEffects m, MonadIO m) => FilePath -> m (Maybe FilePath)
|
||||
nixFilePath :: MonadEffects m => FilePath -> m (Maybe FilePath)
|
||||
nixFilePath path = do
|
||||
path <- makeAbsolutePath path
|
||||
exists <- doesDirectoryExist path
|
||||
|
|
|
@ -46,10 +46,11 @@ module Nix.Parser
|
|||
, whiteSpace
|
||||
) where
|
||||
|
||||
import Prelude hiding (readFile)
|
||||
|
||||
import Control.Applicative hiding (many, some)
|
||||
import Control.DeepSeq
|
||||
import Control.Monad
|
||||
import Control.Monad.IO.Class
|
||||
import Data.Char (isAlpha, isDigit, isSpace)
|
||||
import Data.Data (Data(..))
|
||||
import Data.Foldable (concat)
|
||||
|
@ -62,11 +63,12 @@ import qualified Data.List.NonEmpty as NE
|
|||
import qualified Data.Map as Map
|
||||
import Data.Text (Text)
|
||||
import Data.Text hiding (map, foldr1, concat, concatMap, zipWith)
|
||||
import qualified Data.Text.IO as T
|
||||
import Data.Text.Encoding
|
||||
import Data.Typeable (Typeable)
|
||||
import Data.Void
|
||||
import GHC.Generics hiding (Prefix)
|
||||
import Nix.Expr hiding (($>))
|
||||
import Nix.Render
|
||||
import Nix.Strings
|
||||
import Text.Megaparsec
|
||||
import Text.Megaparsec.Char
|
||||
|
@ -357,11 +359,11 @@ nixSet = annotateLocation1 ((isRec <*> braces nixBinders) <?> "set") where
|
|||
isRec = (reserved "rec" $> NRecSet <?> "recursive set")
|
||||
<+> pure NSet
|
||||
|
||||
parseNixFile :: MonadIO m => FilePath -> m (Result NExpr)
|
||||
parseNixFile :: MonadFile m => FilePath -> m (Result NExpr)
|
||||
parseNixFile =
|
||||
parseFromFileEx $ stripAnnotation <$> (whiteSpace *> nixToplevelForm <* eof)
|
||||
|
||||
parseNixFileLoc :: MonadIO m => FilePath -> m (Result NExprLoc)
|
||||
parseNixFileLoc :: MonadFile m => FilePath -> m (Result NExprLoc)
|
||||
parseNixFileLoc = parseFromFileEx (whiteSpace *> nixToplevelForm <* eof)
|
||||
|
||||
parseNixText :: Text -> Result NExpr
|
||||
|
@ -439,9 +441,9 @@ type Parser = ParsecT Void Text Identity
|
|||
|
||||
data Result a = Success a | Failure Doc deriving (Show, Functor)
|
||||
|
||||
parseFromFileEx :: MonadIO m => Parser a -> FilePath -> m (Result a)
|
||||
parseFromFileEx :: MonadFile m => Parser a -> FilePath -> m (Result a)
|
||||
parseFromFileEx p path = do
|
||||
txt <- liftIO (T.readFile path)
|
||||
txt <- decodeUtf8 <$> readFile path
|
||||
return $ either (Failure . text . parseErrorPretty' txt) Success
|
||||
$ parse p path txt
|
||||
|
||||
|
|
Loading…
Reference in a new issue