-- Copyright (c) Facebook, Inc. and its affiliates.
--
-- This source code is licensed under the MIT license found in the
-- LICENSE file in the root directory of this source tree.
--
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
module Retrie.Monad
  ( -- * Retrie Computations
    Retrie
  , addImports
  , apply
  , applyWithStrategy
  , applyWithUpdate
  , applyWithUpdateAndStrategy
  , focus
  , ifChanged
  , iterateR
  , query
  , queryWithUpdate
  , topDownPrune
    -- * Internal
  , getGroundTerms
  , liftRWST
  , runRetrie
  ) where

import Control.Monad.IO.Class
import Control.Monad.State.Strict
import Control.Monad.RWS
import Control.Monad.Writer.Strict
import Data.Foldable

import Retrie.Context
import Retrie.CPP
import Retrie.ExactPrint hiding (rs)
import Retrie.Fixity
import Retrie.GroundTerms
import Retrie.Query
import Retrie.Replace
import Retrie.Substitution
import Retrie.SYB
import Retrie.Types
import Retrie.Universe

-------------------------------------------------------------------------------

-- | The 'Retrie' monad is essentially 'IO', plus state containing the module
-- that is being transformed. __It is run once per target file.__
--
-- It is special because it also allows Retrie to extract a set of 'GroundTerms'
-- from the 'Retrie' computation /without evaluating it/.
--
-- Retrie uses the ground terms to select which files to target. This is the
-- key optimization that allows Retrie to handle large codebases.
--
-- Note: Due to technical limitations, we cannot extract ground terms if you
-- use 'liftIO' before calling one of 'apply', 'focus', or 'query' at least
-- once. This will cause Retrie to attempt to parse every module in the target
-- directory. In this case, please add a call to 'focus' before the call to
-- 'liftIO'.
data Retrie a where
  Bind :: Retrie b -> (b -> Retrie a) -> Retrie a
  Inst :: RetrieInstruction a -> Retrie a
  Pure :: a -> Retrie a

data RetrieInstruction a where
  Focus :: [GroundTerms] -> RetrieInstruction ()
  Tell :: Change -> RetrieInstruction ()
  IfChanged :: Retrie () -> Retrie () -> RetrieInstruction ()
  Compute :: RetrieComp a -> RetrieInstruction a

type RetrieComp = RWST FixityEnv Change (CPP AnnotatedModule) IO

singleton :: RetrieInstruction a -> Retrie a
singleton :: forall a. RetrieInstruction a -> Retrie a
singleton = forall a. RetrieInstruction a -> Retrie a
Inst

liftRWST :: RetrieComp a -> Retrie a
liftRWST :: forall a. RetrieComp a -> Retrie a
liftRWST = forall a. RetrieInstruction a -> Retrie a
singleton forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. RetrieComp a -> RetrieInstruction a
Compute

-- Note [Retrie Monad]
-- We want to extract a set of ground terms (See Note [Ground Terms])
-- from a 'Retrie' computation corresponding to the ground terms of
-- the _first_ rewrite application. To do so, we keep the chain of
-- binds associated to the right (normal form) so an application is
-- always at the head of the chain. This allows us to look at the
-- ground terms without evaluating the computation.
--
-- We _must_ be able to get ground terms without evaluating, because
-- we use them to filter the set of files on which we run the
-- computation itself. This is why we can't simply use a writer.

-- | We want a right-associated chain of binds, because then we can inspect
-- the instructions in a list-like fashion. We could re-associate in the Monad
-- instance, but that leads to a quadratic bind operation. Instead, we use the
-- view technique.
--
-- Right-associativity is guaranteed because the left side of ':>>='
-- can never be another 'Retrie' computation. It is a primitive
-- 'RetrieInstruction'.
data RetrieView a where
  Return :: a -> RetrieView a
  (:>>=) :: RetrieInstruction b -> (b -> Retrie a) -> RetrieView a

view :: Retrie a -> RetrieView a
view :: forall a. Retrie a -> RetrieView a
view (Pure a
x) = forall a. a -> RetrieView a
Return a
x
view (Inst RetrieInstruction a
inst) = RetrieInstruction a
inst forall b a. RetrieInstruction b -> (b -> Retrie a) -> RetrieView a
:>>= forall (m :: * -> *) a. Monad m => a -> m a
return
view (Bind (Pure b
x) b -> Retrie a
k) = forall a. Retrie a -> RetrieView a
view (b -> Retrie a
k b
x)
view (Bind (Inst RetrieInstruction b
inst) b -> Retrie a
k) = RetrieInstruction b
inst forall b a. RetrieInstruction b -> (b -> Retrie a) -> RetrieView a
:>>= b -> Retrie a
k
view (Bind (Bind Retrie b
m b -> Retrie b
k1) b -> Retrie a
k2) = forall a. Retrie a -> RetrieView a
view (forall b a. Retrie b -> (b -> Retrie a) -> Retrie a
Bind Retrie b
m (b -> Retrie b
k1 forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> b -> Retrie a
k2))

-------------------------------------------------------------------------------
-- Instances

instance Functor Retrie where
  fmap :: forall a b. (a -> b) -> Retrie a -> Retrie b
fmap = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM

instance Applicative Retrie where
  pure :: forall a. a -> Retrie a
pure = forall a. a -> Retrie a
Pure
  <*> :: forall a b. Retrie (a -> b) -> Retrie a -> Retrie b
(<*>) = forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap

instance Monad Retrie where
  return :: forall a. a -> Retrie a
return = forall a. a -> Retrie a
Pure
  >>= :: forall b a. Retrie b -> (b -> Retrie a) -> Retrie a
(>>=) = forall b a. Retrie b -> (b -> Retrie a) -> Retrie a
Bind

instance MonadIO Retrie where
  liftIO :: forall a. IO a -> Retrie a
liftIO = forall a. RetrieInstruction a -> Retrie a
singleton forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. RetrieComp a -> RetrieInstruction a
Compute forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO

-------------------------------------------------------------------------------
-- Running

-- | Run the 'Retrie' monad.
runRetrie
  :: FixityEnv
  -> Retrie a
  -> CPP AnnotatedModule
  -> IO (a, CPP AnnotatedModule, Change)
runRetrie :: forall a.
FixityEnv
-> Retrie a
-> CPP AnnotatedModule
-> IO (a, CPP AnnotatedModule, Change)
runRetrie FixityEnv
fixities Retrie a
retrie = forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST (forall a. Retrie a -> RetrieComp a
getComp Retrie a
retrie) FixityEnv
fixities

-- | Helper to extract the ground terms from a 'Retrie' computation.
getGroundTerms :: Retrie a -> [GroundTerms]
getGroundTerms :: forall a. Retrie a -> [GroundTerms]
getGroundTerms = forall a. RetrieView a -> [GroundTerms]
eval forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Retrie a -> RetrieView a
view
  where
    eval :: RetrieView a -> [GroundTerms]
    eval :: forall a. RetrieView a -> [GroundTerms]
eval Return{} = [] -- The computation is empty!
    eval (RetrieInstruction b
inst :>>= b -> Retrie a
k) =
      case RetrieInstruction b
inst of
        Focus [GroundTerms]
gts -> [GroundTerms]
gts
        Tell Change
_ -> forall a. Retrie a -> [GroundTerms]
getGroundTerms forall a b. (a -> b) -> a -> b
$ b -> Retrie a
k ()
        IfChanged Retrie ()
retrie1 Retrie ()
retrie2
          | gts :: [GroundTerms]
gts@(GroundTerms
_:[GroundTerms]
_) <- forall a. Retrie a -> [GroundTerms]
getGroundTerms Retrie ()
retrie1 -> [GroundTerms]
gts
          | gts :: [GroundTerms]
gts@(GroundTerms
_:[GroundTerms]
_) <- forall a. Retrie a -> [GroundTerms]
getGroundTerms Retrie ()
retrie2 -> [GroundTerms]
gts
          | Bool
otherwise -> forall a. Retrie a -> [GroundTerms]
getGroundTerms forall a b. (a -> b) -> a -> b
$ b -> Retrie a
k ()
        -- If we reach actual computation, we have to give up. The only
        -- way this can currently happen is if 'liftIO' is called before
        -- any focusing is done.
        Compute RetrieComp b
_ -> []

-- | Reflect the reified monadic computation.
getComp :: Retrie a -> RetrieComp a
getComp :: forall a. Retrie a -> RetrieComp a
getComp = forall {a}.
RetrieView a -> RWST FixityEnv Change (CPP AnnotatedModule) IO a
eval forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Retrie a -> RetrieView a
view
  where
    eval :: RetrieView a -> RWST FixityEnv Change (CPP AnnotatedModule) IO a
eval (Return a
x) = forall (m :: * -> *) a. Monad m => a -> m a
return a
x
    eval (RetrieInstruction b
inst :>>= b -> Retrie a
k) = forall {a}. RetrieInstruction a -> RetrieComp a
evalInst RetrieInstruction b
inst forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. Retrie a -> RetrieComp a
getComp forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Retrie a
k

    evalInst :: RetrieInstruction a -> RetrieComp a
evalInst (Focus [GroundTerms]
_) = forall (m :: * -> *) a. Monad m => a -> m a
return ()
    evalInst (Tell Change
c) = forall w (m :: * -> *). MonadWriter w m => w -> m ()
tell Change
c
    evalInst (IfChanged Retrie ()
r1 Retrie ()
r2) = RetrieComp () -> RetrieComp () -> RetrieComp ()
ifChangedComp (forall a. Retrie a -> RetrieComp a
getComp Retrie ()
r1) (forall a. Retrie a -> RetrieComp a
getComp Retrie ()
r2)
    evalInst (Compute RetrieComp a
m) = RetrieComp a
m

-------------------------------------------------------------------------------
-- Public API

-- | Use the given queries/rewrites to select files for rewriting.
-- Does not actually perform matching. This is useful if the queries/rewrites
-- which best determine which files to target are not the first ones you run,
-- and when you need to 'liftIO' before running any queries/rewrites.
focus :: Data k => [Query k v] -> Retrie ()
focus :: forall k v. Data k => [Query k v] -> Retrie ()
focus [] = forall (m :: * -> *) a. Monad m => a -> m a
return ()
focus [Query k v]
qs = forall a. RetrieInstruction a -> Retrie a
singleton forall a b. (a -> b) -> a -> b
$ [GroundTerms] -> RetrieInstruction ()
Focus forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall k v. Data k => Query k v -> GroundTerms
groundTerms [Query k v]
qs

-- | Apply a set of rewrites. By default, rewrites are applied top-down,
-- pruning the traversal at successfully changed AST nodes. See 'topDownPrune'.
apply :: [Rewrite Universe] -> Retrie ()
apply :: [Rewrite Universe] -> Retrie ()
apply = ContextUpdater
-> Strategy (TransformT (WriterT Change IO))
-> [Rewrite Universe]
-> Retrie ()
applyWithUpdateAndStrategy ContextUpdater
updateContext forall (m :: * -> *).
Monad m =>
Strategy (TransformT (WriterT Change m))
topDownPrune

-- | Apply a set of rewrites with a custom context-update function.
applyWithUpdate
  :: ContextUpdater -> [Rewrite Universe] -> Retrie ()
applyWithUpdate :: ContextUpdater -> [Rewrite Universe] -> Retrie ()
applyWithUpdate ContextUpdater
updCtxt = ContextUpdater
-> Strategy (TransformT (WriterT Change IO))
-> [Rewrite Universe]
-> Retrie ()
applyWithUpdateAndStrategy ContextUpdater
updCtxt forall (m :: * -> *).
Monad m =>
Strategy (TransformT (WriterT Change m))
topDownPrune

-- | Apply a set of rewrites with a custom traversal strategy.
applyWithStrategy
  :: Strategy (TransformT (WriterT Change IO))
  -> [Rewrite Universe]
  -> Retrie ()
applyWithStrategy :: Strategy (TransformT (WriterT Change IO))
-> [Rewrite Universe] -> Retrie ()
applyWithStrategy = ContextUpdater
-> Strategy (TransformT (WriterT Change IO))
-> [Rewrite Universe]
-> Retrie ()
applyWithUpdateAndStrategy ContextUpdater
updateContext

-- | Apply a set of rewrites with custom context-update and traversal strategy.
applyWithUpdateAndStrategy
  :: ContextUpdater
  -> Strategy (TransformT (WriterT Change IO))
  -> [Rewrite Universe]
  -> Retrie ()
applyWithUpdateAndStrategy :: ContextUpdater
-> Strategy (TransformT (WriterT Change IO))
-> [Rewrite Universe]
-> Retrie ()
applyWithUpdateAndStrategy ContextUpdater
_       Strategy (TransformT (WriterT Change IO))
_        []  = forall (m :: * -> *) a. Monad m => a -> m a
return ()
applyWithUpdateAndStrategy ContextUpdater
updCtxt Strategy (TransformT (WriterT Change IO))
strategy [Rewrite Universe]
rrs = do
  forall k v. Data k => [Query k v] -> Retrie ()
focus [Rewrite Universe]
rrs
  forall a. RetrieInstruction a -> Retrie a
singleton forall a b. (a -> b) -> a -> b
$ forall a. RetrieComp a -> RetrieInstruction a
Compute forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) r s w.
Monad m =>
(r -> s -> WriterT w m s) -> RWST r w s m ()
rs forall a b. (a -> b) -> a -> b
$ \ FixityEnv
fixityEnv ->
    forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip forall (m :: * -> *) ast1 ast2.
Monad m =>
Annotated ast1 -> (ast1 -> TransformT m ast2) -> m (Annotated ast2)
transformA forall a b. (a -> b) -> a -> b
$
      forall (m :: * -> *) c.
Monad m =>
Strategy m
-> GenericQ Bool -> GenericCU m c -> GenericMC m c -> GenericMC m c
everywhereMWithContextBut Strategy (TransformT (WriterT Change IO))
strategy
        (forall a b. a -> b -> a
const Bool
False) ContextUpdater
updCtxt forall a (m :: * -> *).
(Data a, MonadIO m) =>
Context -> a -> TransformT (WriterT Change m) a
replace (FixityEnv -> Rewriter -> Rewriter -> Context
emptyContext FixityEnv
fixityEnv Rewriter
m Rewriter
d)
  where
    m :: Rewriter
m = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall ast. Matchable ast => Rewrite ast -> Rewriter
mkRewriter [Rewrite Universe]
rrs
    d :: Rewriter
d = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall ast. Matchable ast => Rewrite ast -> Rewriter
mkRewriter forall a b. (a -> b) -> a -> b
$ forall ast. [Rewrite ast] -> [Rewrite ast]
rewritesWithDependents [Rewrite Universe]
rrs

-- | Query the AST. Each match returns the context of the match, a substitution
-- mapping quantifiers to matched subtrees, and the query's value.
query :: [Query Universe v] -> Retrie [(Context, Substitution, v)]
query :: forall v. [Query Universe v] -> Retrie [(Context, Substitution, v)]
query = forall v.
ContextUpdater
-> [Query Universe v] -> Retrie [(Context, Substitution, v)]
queryWithUpdate ContextUpdater
updateContext

-- | Query the AST with a custom context update function.
queryWithUpdate
  :: ContextUpdater
  -> [Query Universe v]
  -> Retrie [(Context, Substitution, v)]
queryWithUpdate :: forall v.
ContextUpdater
-> [Query Universe v] -> Retrie [(Context, Substitution, v)]
queryWithUpdate ContextUpdater
_       [] = forall (m :: * -> *) a. Monad m => a -> m a
return []
queryWithUpdate ContextUpdater
updCtxt [Query Universe v]
qs = do
  forall k v. Data k => [Query k v] -> Retrie ()
focus [Query Universe v]
qs
  forall a. RetrieInstruction a -> Retrie a
singleton forall a b. (a -> b) -> a -> b
$ forall a. RetrieComp a -> RetrieInstruction a
Compute forall a b. (a -> b) -> a -> b
$ do
    FixityEnv
fixityEnv <- forall r (m :: * -> *). MonadReader r m => m r
ask
    CPP AnnotatedModule
cpp <- forall s (m :: * -> *). MonadState s m => m s
get
    [[(Context, Substitution, v)]]
results <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM (forall (t :: * -> *) a. Foldable t => t a -> [a]
toList CPP AnnotatedModule
cpp) forall a b. (a -> b) -> a -> b
$ \AnnotatedModule
modl -> do
      Annotated [(Context, Substitution, v)]
annotatedResults <- forall (m :: * -> *) ast1 ast2.
Monad m =>
Annotated ast1 -> (ast1 -> TransformT m ast2) -> m (Annotated ast2)
transformA AnnotatedModule
modl forall a b. (a -> b) -> a -> b
$
        forall (m :: * -> *) c r.
(Monad m, Monoid r) =>
GenericQ Bool
-> GenericCU m c -> GenericMCQ m c r -> GenericMCQ m c r
everythingMWithContextBut
          (forall a b. a -> b -> a
const Bool
False)
          ContextUpdater
updCtxt
          (forall a v.
Typeable a =>
Matcher v
-> Context -> a -> TransformT IO [(Context, Substitution, v)]
genericQ Matcher v
matcher)
          (FixityEnv -> Rewriter -> Rewriter -> Context
emptyContext FixityEnv
fixityEnv forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty)
      forall (m :: * -> *) a. Monad m => a -> m a
return (forall ast. Annotated ast -> ast
astA Annotated [(Context, Substitution, v)]
annotatedResults)
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[(Context, Substitution, v)]]
results
  where
    matcher :: Matcher v
matcher = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap forall ast v. Matchable ast => Query ast v -> Matcher v
mkMatcher [Query Universe v]
qs

-- | If the first 'Retrie' computation makes a change to the module,
-- run the second 'Retrie' computation.
ifChanged :: Retrie () -> Retrie () -> Retrie ()
ifChanged :: Retrie () -> Retrie () -> Retrie ()
ifChanged Retrie ()
r1 Retrie ()
r2 = forall a. RetrieInstruction a -> Retrie a
singleton forall a b. (a -> b) -> a -> b
$ Retrie () -> Retrie () -> RetrieInstruction ()
IfChanged Retrie ()
r1 Retrie ()
r2

ifChangedComp :: RetrieComp () -> RetrieComp () -> RetrieComp ()
ifChangedComp :: RetrieComp () -> RetrieComp () -> RetrieComp ()
ifChangedComp RetrieComp ()
r1 RetrieComp ()
r2 = do
  (()
_, Change
c) <- forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen RetrieComp ()
r1
  case Change
c of
    Change{} -> RetrieComp ()
r2
    Change
NoChange  -> forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Iterate given 'Retrie' computation until it no longer makes changes,
-- or N times, whichever happens first.
iterateR :: Int -> Retrie () -> Retrie ()
iterateR :: Int -> Retrie () -> Retrie ()
iterateR Int
n Retrie ()
r = forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
n forall a. Ord a => a -> a -> Bool
> Int
0) forall a b. (a -> b) -> a -> b
$ Retrie () -> Retrie () -> Retrie ()
ifChanged Retrie ()
r forall a b. (a -> b) -> a -> b
$ Int -> Retrie () -> Retrie ()
iterateR (Int
nforall a. Num a => a -> a -> a
-Int
1) Retrie ()
r
-- By implementing in terms of 'ifChanged', we expose the ground terms for 'r'

-- | Add imports to the module.
addImports :: AnnotatedImports -> Retrie ()
addImports :: AnnotatedImports -> Retrie ()
addImports AnnotatedImports
imports = forall a. RetrieInstruction a -> Retrie a
singleton forall a b. (a -> b) -> a -> b
$ Change -> RetrieInstruction ()
Tell forall a b. (a -> b) -> a -> b
$ [Replacement] -> [AnnotatedImports] -> Change
Change [] [AnnotatedImports
imports]

-- | Top-down traversal that does not descend into changed AST nodes.
-- Default strategy used by 'apply'.
topDownPrune :: Monad m => Strategy (TransformT (WriterT Change m))
topDownPrune :: forall (m :: * -> *).
Monad m =>
Strategy (TransformT (WriterT Change m))
topDownPrune a -> TransformT (WriterT Change m) a
p a -> TransformT (WriterT Change m) a
cs a
x = do
  (a
p', Change
c) <- forall (m :: * -> *) w a.
(Monad m, Monoid w) =>
TransformT (WriterT w m) a -> TransformT (WriterT w m) (a, w)
listenTransformT (a -> TransformT (WriterT Change m) a
p a
x)
  case Change
c of
    Change{} -> forall (m :: * -> *) a. Monad m => a -> m a
return a
p'
    Change
NoChange  -> a -> TransformT (WriterT Change m) a
cs a
x

-- | Monad transformer shuffling.
listenTransformT
  :: (Monad m, Monoid w)
  => TransformT (WriterT w m) a -> TransformT (WriterT w m) (a, w)
listenTransformT :: forall (m :: * -> *) w a.
(Monad m, Monoid w) =>
TransformT (WriterT w m) a -> TransformT (WriterT w m) (a, w)
listenTransformT (TransformT RWST () [String] Int (WriterT w m) a
rwst) =
  forall (m :: * -> *) a. RWST () [String] Int m a -> TransformT m a
TransformT forall a b. (a -> b) -> a -> b
$ forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ ()
r Int
s -> do
    ((a
x,Int
y,[String]
z),w
w) <- forall w (m :: * -> *) a. MonadWriter w m => m a -> m (a, w)
listen forall a b. (a -> b) -> a -> b
$ forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
runRWST RWST () [String] Int (WriterT w m) a
rwst ()
r Int
s
    forall (m :: * -> *) a. Monad m => a -> m a
return ((a
x,w
w),Int
y,[String]
z) -- naming is hard

-- | Like 'rws', but builds 'RWST' instead of 'RWS',
-- takes argument in WriterT layer, and specialized to ().
rs :: Monad m => (r -> s -> WriterT w m s) -> RWST r w s m ()
rs :: forall (m :: * -> *) r s w.
Monad m =>
(r -> s -> WriterT w m s) -> RWST r w s m ()
rs r -> s -> WriterT w m s
f = forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
RWST forall a b. (a -> b) -> a -> b
$ \ r
r s
s -> do
  (s
s', w
w) <- forall w (m :: * -> *) a. WriterT w m a -> m (a, w)
runWriterT (r -> s -> WriterT w m s
f r
r s
s)
  forall (m :: * -> *) a. Monad m => a -> m a
return ((), s
s', w
w)