Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
natefaubion committed Apr 17, 2017
1 parent 3e9e7e1 commit de3a177
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Control/Monad/Run.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Control.Monad.Aff (Aff)
import Control.Monad.Aff.Class (class MonadAff, liftAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (class MonadEff, liftEff)
import Control.Monad.Free (Free, liftF, runFree, foldFree, substFree, resume)
import Control.Monad.Free (Free, liftF, runFree, foldFree, hoistFree, resume)
import Control.Monad.Rec.Class (class MonadRec, Step(..))
import Data.Either (Either(..))
import Data.Newtype (class Newtype, unwrap, wrap, over)
Expand Down Expand Up @@ -106,23 +106,38 @@ liftEffect
RProxy sym f
f a
Run r2 a
liftEffect _ f = RunM $ liftF $ RunF (FTag (reflectSymbol (SProxy SProxy sym))) (mkFBox (liftYoneda f))
liftEffect _ f = RunM $ liftF $ RunF tag box
where
tag FTag
tag = FTag (reflectSymbol (SProxy SProxy sym))

box FBox a
box = mkFBox (liftYoneda f)

-- | Lifts a base effect into the `Run` Monad (eg. `Eff`, `Aff`, or `IO`).
liftBase
r f a
. Functor f
f a
Run (baseRBase f | r) a
liftBase f = RunM $ liftF $ RunF (FTag "base") (mkFBox (liftYoneda f))
liftBase f = RunM $ liftF $ RunF tag box
where
tag FTag
tag = FTag "base"

box FBox a
box = mkFBox (liftYoneda f)

-- | Reflects the next instruction or the final value if there are no more
-- | instructions.
peel
a r
. Run r a
Either (RunF r (Run r a)) a
peel (RunM r) = unsafeCoerce (resume r)
peel (RunM r) = coerceR (resume r)
where
coerceR Either (RunF r (Free (RunF r) a)) a Either (RunF r (Run r a)) a
coerceR = unsafeCoerce

-- | Enqueues an instruction in the `Run` Monad.
send
Expand Down Expand Up @@ -180,10 +195,10 @@ interpret
(f ~> m)
Run r1 a
Run r3 a
interpret _ k = over RunM (substFree (\a → liftF (go a)))
interpret _ k = over RunM (hoistFree go)
where
tag =
reflectSymbol (SProxy SProxy sym)
tag String
tag = reflectSymbol (SProxy SProxy sym)

go RunF r1 ~> RunF r3
go r@(RunF (FTag tag') f) =
Expand Down

0 comments on commit de3a177

Please sign in to comment.