@@ -141,10 +141,10 @@ nverr :: forall e t f s m a . (MonadNix e t f m, Exception s) => s -> m a
141141nverr = evalError @ (NValue t f m )
142142
143143currentPos :: forall e m . (MonadReader e m , Has e SrcSpan ) => m SrcSpan
144- currentPos = asks ( view hasLens)
144+ currentPos = asks $ view hasLens
145145
146146wrapExprLoc :: SrcSpan -> NExprLocF r -> NExprLoc
147- wrapExprLoc span x = Fix ( Fix (NSym_ span " <?>" ) <$ x)
147+ wrapExprLoc span x = Fix $ Fix (NSym_ span " <?>" ) <$ x
148148{-# inline wrapExprLoc #-}
149149
150150-- 2021-01-07: NOTE: This instance belongs to be beside MonadEval type class.
@@ -172,27 +172,27 @@ instance MonadNix e t f m => MonadEval (NValue t f m) m where
172172 )
173173 ms
174174 where
175- attr = Text. intercalate " ." ( NE. toList ks)
175+ attr = Text. intercalate " ." $ NE. toList ks
176176
177177 evalCurPos = do
178178 scope <- currentScopes
179179 span @ (SrcSpan delta _) <- currentPos
180180 addProvenance @ _ @ _ @ (NValue t f m )
181- (Provenance scope ( NSym_ span " __curPos" ) ) <$>
181+ (Provenance scope $ NSym_ span " __curPos" ) <$>
182182 toValue delta
183183
184184 evaledSym name val = do
185185 scope <- currentScopes
186186 span <- currentPos
187187 pure $
188188 addProvenance @ _ @ _ @ (NValue t f m )
189- (Provenance scope ( NSym_ span name) )
189+ (Provenance scope $ NSym_ span name)
190190 val
191191
192192 evalConstant c = do
193193 scope <- currentScopes
194194 span <- currentPos
195- pure $ nvConstantP (Provenance scope ( NConstant_ span c) ) c
195+ pure $ nvConstantP (Provenance scope $ NConstant_ span c) c
196196
197197 evalString =
198198 maybe
@@ -205,7 +205,7 @@ instance MonadNix e t f m => MonadEval (NValue t f m) m where
205205 nvStrP
206206 (Provenance
207207 scope
208- (NStr_ span ( DoubleQuoted [Plain ( stringIgnoreContext ns)]) )
208+ (NStr_ span $ DoubleQuoted [Plain $ stringIgnoreContext ns] )
209209 )
210210 ns
211211 )
@@ -214,13 +214,13 @@ instance MonadNix e t f m => MonadEval (NValue t f m) m where
214214 evalLiteralPath p = do
215215 scope <- currentScopes
216216 span <- currentPos
217- nvPathP (Provenance scope ( NLiteralPath_ span p) ) <$>
217+ nvPathP (Provenance scope $ NLiteralPath_ span p) <$>
218218 makeAbsolutePath @ t @ f @ m p
219219
220220 evalEnvPath p = do
221221 scope <- currentScopes
222222 span <- currentPos
223- nvPathP (Provenance scope ( NEnvPath_ span p) ) <$>
223+ nvPathP (Provenance scope $ NEnvPath_ span p) <$>
224224 findEnvPath @ t @ f @ m p
225225
226226 evalUnary op arg = do
@@ -236,20 +236,23 @@ instance MonadNix e t f m => MonadEval (NValue t f m) m where
236236 evalWith c b = do
237237 scope <- currentScopes
238238 span <- currentPos
239- ( \ b -> addProvenance ( Provenance scope ( NWith_ span Nothing ( pure b))) b)
240- <$> evalWithAttrSet c b
239+ let f = join $ addProvenance . Provenance scope . NWith_ span Nothing . pure
240+ f <$> evalWithAttrSet c b
241241
242242 evalIf c t f = do
243243 scope <- currentScopes
244244 span <- currentPos
245245 b <- fromValue c
246246
247247 let
248- fun x y = addProvenance (Provenance scope (NIf_ span (pure c) x y))
248+ fun x y z = addProvenance (Provenance scope $ NIf_ span (pure c) x y) z
249+ -- Note: join == \ f x -> f x x
250+ false = join (fun Nothing . pure ) <$> f
251+ true = join (flip fun Nothing . pure ) <$> t
249252
250253 bool
251- ( ( \ f' -> fun Nothing ( pure f') f') <$> f )
252- ( ( \ t' -> fun ( pure t') Nothing t') <$> t )
254+ false
255+ true
253256 b
254257
255258 evalAssert c body =
@@ -260,25 +263,23 @@ instance MonadNix e t f m => MonadEval (NValue t f m) m where
260263 (nverr $ Assertion span c)
261264 (do
262265 scope <- currentScopes
263- (\ b ->
264- addProvenance (Provenance scope (NAssert_ span (pure c) (pure b))) b
265- ) <$>
266- body
266+ let f = join (addProvenance . Provenance scope . NAssert_ span (pure c) . pure )
267+ f <$> body
267268 )
268269 b
269270
270271 evalApp f x = do
271272 scope <- currentScopes
272273 span <- currentPos
273- addProvenance (Provenance scope ( NBinary_ span NApp (pure f) Nothing ) ) <$>
274+ addProvenance (Provenance scope $ NBinary_ span NApp (pure f) Nothing ) <$>
274275 (callFunc f =<< defer x)
275276
276277 evalAbs p k = do
277278 scope <- currentScopes
278279 span <- currentPos
279280 pure $
280281 nvClosureP
281- (Provenance scope ( NAbs_ span (Nothing <$ p) Nothing ) )
282+ (Provenance scope $ NAbs_ span (Nothing <$ p) Nothing )
282283 (void p)
283284 (\ arg -> snd <$> k (pure arg) (\ _ b -> (() , ) <$> b))
284285
@@ -293,7 +294,7 @@ callFunc
293294 -> m (NValue t f m )
294295callFunc fun arg =
295296 do
296- frames :: Frames <- asks ( view hasLens)
297+ frames :: Frames <- asks $ view hasLens
297298 when (length frames > 2000 ) $ throwError $ ErrorCall " Function call stack exhausted"
298299
299300 fun' <- demand fun
@@ -304,8 +305,8 @@ callFunc fun arg =
304305 span <- currentPos
305306 withFrame Info ((Calling @ m @ (NValue t f m )) name span ) (f arg)
306307 (NVSet m _) | Just f <- M. lookup " __functor" m ->
307- (( `callFunc` arg) <=< (`callFunc` fun') ) =<< demand f
308- x -> throwError $ ErrorCall $ " Attempt to call non-function: " <> show x
308+ (`callFunc` arg) =<< (`callFunc` fun') =<< demand f
309+ _x -> throwError $ ErrorCall $ " Attempt to call non-function: " <> show _x
309310
310311execUnaryOp
311312 :: (Framed e m , MonadCited t f m , Show t )
@@ -321,12 +322,12 @@ execUnaryOp scope span op arg = do
321322 (NNeg , NInt i ) -> unaryOp $ NInt (- i)
322323 (NNeg , NFloat f) -> unaryOp $ NFloat (- f)
323324 (NNot , NBool b ) -> unaryOp $ NBool (not b)
324- _ ->
325- throwError $ ErrorCall $ " unsupported argument type for unary operator " <> show op
326- x ->
327- throwError $ ErrorCall $ " argument to unary operator must evaluate to an atomic type: " <> show x
325+ _seq ->
326+ throwError $ ErrorCall $ " unsupported argument type for unary operator " <> show _seq
327+ _x ->
328+ throwError $ ErrorCall $ " argument to unary operator must evaluate to an atomic type: " <> show _x
328329 where
329- unaryOp = pure . nvConstantP (Provenance scope ( NUnary_ span op ( pure arg)) )
330+ unaryOp = pure . nvConstantP (Provenance scope $ NUnary_ span op $ pure arg)
330331
331332execBinaryOp
332333 :: forall e t f m
@@ -371,7 +372,7 @@ execBinaryOp scope span op lval rarg =
371372 )
372373 =<< fromValue lval
373374
374- boolOp rval = toBoolOp ( pure rval)
375+ boolOp rval = toBoolOp $ pure rval
375376
376377 bypass = toBoolOp Nothing
377378
@@ -511,7 +512,7 @@ addTracing k v = do
511512#else
512513 show $ void x
513514#endif
514- else prettyNix ( Fix ( Fix (NSym " ?" ) <$ x))
515+ else prettyNix $ Fix $ Fix (NSym " ?" ) <$ x
515516 msg x = pretty (" eval: " <> replicate depth ' ' ) <> x
516517 loc <- renderLocation span $ msg rendered <> " ...\n "
517518 putStr $ show loc
@@ -526,7 +527,7 @@ evalExprLoc expr =
526527 let
527528 pTracedAdi =
528529 bool
529- (adi Eval. evalContent Eval. addMetaInfo)
530+ Eval. framedEvalExprLoc
530531 (join . (`runReaderT` (0 :: Int )) .
531532 adi
532533 (addTracing Eval. evalContent)
0 commit comments