Simplify the definitions of adi and adiM, according to our actual usage

This commit is contained in:
John Wiegley 2018-03-30 23:34:57 -07:00
parent b89b795abe
commit c2c4d93585
2 changed files with 14 additions and 27 deletions

View file

@ -350,21 +350,21 @@ evalKeyName dyn (DynamicKey k)
contextualExprEval :: forall m. MonadNix m => NExprLoc -> m (NValue m)
contextualExprEval =
runIdentity . snd . adi @() (eval . annotated . getCompose) psi
adi (eval . annotated . getCompose) psi
where
psi k v@(Fix x) = fmap (fmap (withExprContext (() <$ x))) (k v)
psi k v@(Fix x) = withExprContext (() <$ x) (k v)
tracingExprEval :: MonadNix m => NExprLoc -> IO (m (NValue m))
tracingExprEval = flip runReaderT (0 :: Int)
. fmap (runIdentity . snd)
. adiM @() (pure <$> eval . annotated . getCompose) psi
tracingExprEval =
flip runReaderT (0 :: Int)
. adiM (pure <$> eval . annotated . getCompose) psi
where
psi k v@(Fix x) = do
depth <- ask
liftIO $ putStrLn $ "eval: " ++ replicate (depth * 2) ' '
++ show (stripAnnotation v)
res <- local succ $
fmap (fmap (fmap (withExprContext (() <$ x)))) (k v)
fmap (withExprContext (() <$ x)) (k v)
liftIO $ putStrLn $ "eval: " ++ replicate (depth * 2) ' ' ++ "."
return res

View file

@ -42,27 +42,14 @@ para f base = h where
-- Essentially, it does for evaluation what recursion schemes do for
-- representation: allows threading layers through existing structure, only
-- in this case through behavior.
adi :: (Monoid b, Applicative s, Traversable t)
adi :: Traversable t
=> (t a -> a)
-> ((Fix t -> (b, s a)) -> Fix t -> (b, s a))
-> Fix t -> (b, s a)
adi f g = g (go . traverse (adi f g) . unFix)
where
go = fmap (fmap f . sequenceA)
-> ((Fix t -> a) -> Fix t -> a)
-> Fix t -> a
adi f g = g (f . fmap (adi f g) . unFix)
adiM :: (Monoid b, Applicative s, Traversable s, Traversable t, Monad m)
adiM :: (Traversable t, Monad m)
=> (t a -> m a)
-> ((Fix t -> m (b, s a)) -> Fix t -> m (b, s a))
-> Fix t -> m (b, s a)
adiM f g = g ((go <=< traverse (adiM f g)) . unFix)
where
go = traverse (traverse f . sequenceA) . sequenceA
adiT :: forall s t m a. (Traversable t, Monad m, Monad s)
=> (t a -> m a)
-> ((Fix t -> s (m a)) -> Fix t -> s (m a))
-> Fix t -> s (m a)
adiT f g = g (go . fmap (adiT f g) . unFix)
where
go :: t (s (m a)) -> s (m a)
go = fmap ((f =<<) . sequenceA) . sequenceA
-> ((Fix t -> m a) -> Fix t -> m a)
-> Fix t -> m a
adiM f g = g ((f <=< traverse (adiM f g)) . unFix)