Skip to content

Commit 8ae9c89

Browse files
committed
Repl: m refactor
1 parent 701c2d9 commit 8ae9c89

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

main/Repl.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ main' iniVal = initState iniVal >>= \s -> flip evalStateT s
126126
| s `Data.List.isPrefixOf` x = m args
127127
| otherwise = optMatcher s xs args
128128

129-
---------------------------------------------------------------------------------
129+
130130
-- * Types
131-
---------------------------------------------------------------------------------
132131

133132
data IState t f m = IState
134133
{ replIt :: Maybe NExprLoc -- ^ Last expression entered
@@ -173,9 +172,8 @@ initState mIni = do
173172

174173
type Repl e t f m = HaskelineT (StateT (IState t f m) m)
175174

176-
---------------------------------------------------------------------------------
175+
177176
-- * Execution
178-
---------------------------------------------------------------------------------
179177

180178
exec
181179
:: forall e t f m
@@ -259,9 +257,8 @@ printValue val = do
259257
| cfgValues cfg -> liftIO . print . prettyNValueProv =<< removeEffects val
260258
| otherwise -> liftIO . print . prettyNValue =<< removeEffects val
261259

262-
---------------------------------------------------------------------------------
260+
263261
-- * Commands
264-
---------------------------------------------------------------------------------
265262

266263
-- :browse command
267264
browse :: (MonadNix e t f m, MonadIO m)
@@ -293,16 +290,20 @@ typeof
293290
-> Repl e t f m ()
294291
typeof args = do
295292
st <- get
296-
mVal <- case Data.HashMap.Lazy.lookup line (replCtx st) of
297-
Just val -> pure $ pure val
298-
Nothing -> do
299-
exec False line
293+
mVal <-
294+
case Data.HashMap.Lazy.lookup line (replCtx st) of
295+
Nothing -> exec False line
296+
Just val -> pure $ pure val
300297

301-
for_ mVal $ \val -> do
302-
s <- lift . lift . showValueType $ val
303-
liftIO $ putStrLn s
298+
traverse_ printValueType mVal
299+
300+
where
301+
line = Data.Text.pack args
302+
printValueType val =
303+
do
304+
s <- lift . lift . showValueType $ val
305+
liftIO $ putStrLn s
304306

305-
where line = Data.Text.pack args
306307

307308
-- :quit command
308309
quit :: (MonadNix e t f m, MonadIO m) => a -> Repl e t f m ()
@@ -317,9 +318,8 @@ setConfig args = case words args of
317318
[opt] -> modify (\s -> s { replCfg = helpSetOptionFunction opt (replCfg s) })
318319
_ -> liftIO $ putStrLn "No such option"
319320

320-
---------------------------------------------------------------------------------
321+
321322
-- * Interactive Shell
322-
---------------------------------------------------------------------------------
323323

324324
-- Prefix tab completer
325325
defaultMatcher :: MonadIO m => [(String, CompletionFunc m)]

src/Nix/Builtins.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,8 @@ tryEval
16441644
tryEval e = catch (onSuccess <$> demand e) (pure . onError)
16451645
where
16461646
onSuccess v = flip nvSet M.empty $ M.fromList
1647-
[("success", nvConstant (NBool True)), ("value", v)]
1647+
[ ("success", nvConstant (NBool True))
1648+
, ("value", v)]
16481649

16491650
onError :: SomeException -> NValue t f m
16501651
onError _ = flip nvSet M.empty $ M.fromList

0 commit comments

Comments
 (0)