File tree 1 file changed +11
-0
lines changed
1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module Control.Monad.Free.Trans
7
7
, hoistFreeT
8
8
, interpret
9
9
, bimapFreeT
10
+ , substFreeT
10
11
, resume
11
12
, runFreeT
12
13
) where
@@ -119,6 +120,16 @@ bimapFreeT :: forall f g m n a. Functor f => Functor n => (f ~> g) -> (m ~> n) -
119
120
bimapFreeT nf nm (Bind e) = runExists (\(Bound a f) -> bound (bimapFreeT nf nm <<< a) (bimapFreeT nf nm <<< f)) e
120
121
bimapFreeT nf nm (FreeT m) = FreeT \_ -> map (nf <<< map (bimapFreeT nf nm)) <$> nm (m unit)
121
122
123
+
124
+ -- | Like `runFreeT`, but for running into some other FreeT without the
125
+ -- | overhead that `MonadRec` incurs.
126
+ substFreeT :: forall a m f g . Monad m => Functor g => (f ~> FreeT g m ) -> FreeT f m a -> FreeT g m a
127
+ substFreeT fBind (Bind e) = runExists (\(Bound a f) -> bound (substFreeT fBind <<< a) (substFreeT fBind <<< f)) e
128
+ substFreeT fBind (FreeT m) = join $ FreeT \_ -> m unit <#> case _ of
129
+ Left val -> Left $ pure val
130
+ Right fFree -> Left $ bound (\_ -> fBind fFree) (substFreeT fBind)
131
+
132
+
122
133
-- | Run a `FreeT` computation to completion.
123
134
runFreeT :: forall f m a . Functor f => MonadRec m => (f (FreeT f m a ) -> m (FreeT f m a )) -> FreeT f m a -> m a
124
135
runFreeT interp = tailRecM (go <=< resume)
You can’t perform that action at this time.
0 commit comments