Skip to content

Commit 089fc98

Browse files
committed
Add runFreeC
1 parent f08daaa commit 089fc98

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,22 @@ runFreeM :: forall f m a. (Functor f, MonadRec m) => (f (Free f a) -> m (Free f
230230
`runFreeM` runs a compuation of type `Free f a` in any `Monad` which supports tail recursion.
231231
See the `MonadRec` type class for more details.
232232

233-
#### `runFreeMC`
233+
#### `runFreeC`
234234

235235
``` purescript
236-
runFreeMC :: forall f m a. (MonadRec m) => Natural f m -> FreeC f a -> m a
236+
runFreeC :: forall f a. (forall a. f a -> a) -> FreeC f a -> a
237237
```
238238

239-
`runFreeMC` is the equivalent of `runFreeM` for type constructors transformed with `Coyoneda`,
239+
`runFreeC` is the equivalent of `runFree` for type constructors transformed with `Coyoneda`,
240+
hence we have no requirement that `f` be a `Functor`.
241+
242+
#### `runFreeCM`
243+
244+
``` purescript
245+
runFreeCM :: forall f m a. (MonadRec m) => Natural f m -> FreeC f a -> m a
246+
```
247+
248+
`runFreeCM` is the equivalent of `runFreeM` for type constructors transformed with `Coyoneda`,
240249
hence we have no requirement that `f` be a `Functor`.
241250

242251

examples/Teletype.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ teletypeN (PutStrLn s a) = const a <$> trace s
2020
teletypeN (GetLine k) = return $ k "fake input"
2121

2222
run :: forall a. Teletype a -> Eff (trace :: Trace) a
23-
run = runFreeMC teletypeN
23+
run = runFreeCM teletypeN
2424

2525
echo = do
2626
a <- getLine

examples/TeletypeCoproduct.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module TeletypeCoproduct where
33
import Control.Apply ((*>))
44
import Control.Alt ((<|>))
55
import Control.Monad.Eff (Eff())
6-
import Control.Monad.Free (FreeC(), liftFC, injC, runFreeMC)
6+
import Control.Monad.Free (FreeC(), liftFC, injC, runFreeCM)
77
import Data.Coyoneda (Natural())
88
import Data.Inject (prj)
99
import Data.Functor.Coproduct (Coproduct())
@@ -62,6 +62,6 @@ tN fa = fromJust $ (teletype1N <$> prj fa) <|>
6262
(teletype3N <$> prj fa)
6363

6464
run :: forall a. T a -> Eff (trace :: Trace) a
65-
run = runFreeMC tN
65+
run = runFreeCM tN
6666

6767
main = run u

src/Control/Monad/Free.purs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module Control.Monad.Free
77
, mapF, injC
88
, runFree
99
, runFreeM
10-
, runFreeMC
10+
, runFreeC
11+
, runFreeCM
1112
) where
1213

1314
import Control.Monad.Trans
@@ -100,8 +101,13 @@ runFreeM fn = tailRecM \f ->
100101
Left fs -> Left <$> fn fs
101102
Right a -> return (Right a)
102103

103-
-- | `runFreeMC` is the equivalent of `runFreeM` for type constructors transformed with `Coyoneda`,
104+
-- | `runFreeC` is the equivalent of `runFree` for type constructors transformed with `Coyoneda`,
104105
-- | hence we have no requirement that `f` be a `Functor`.
105-
runFreeMC :: forall f m a. (MonadRec m) => Natural f m -> FreeC f a -> m a
106-
runFreeMC nat = runFreeM (liftCoyonedaTF nat)
106+
runFreeC :: forall f a. (forall a. f a -> a) -> FreeC f a -> a
107+
runFreeC nat = runIdentity <<< runFreeCM (Identity <<< nat)
108+
109+
-- | `runFreeCM` is the equivalent of `runFreeM` for type constructors transformed with `Coyoneda`,
110+
-- | hence we have no requirement that `f` be a `Functor`.
111+
runFreeCM :: forall f m a. (MonadRec m) => Natural f m -> FreeC f a -> m a
112+
runFreeCM nat = runFreeM (liftCoyonedaTF nat)
107113

0 commit comments

Comments
 (0)