Skip to content

add substFreeT #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2019
Merged

Conversation

safareli
Copy link
Contributor

@safareli safareli commented Aug 14, 2019


-- | Like `runFreeT`, but for running into some other FreeT without the
-- | overhead that `MonadRec` incurs.
substFreeT :: forall a m f g. Monad m => Functor g => (f ~> FreeT g m) -> FreeT f m a -> FreeT g m a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: Monad m is needed because of pure val

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not Applicative?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Monad m => Applicative (FreeT f m) because Apply is implemented using ap

@safareli
Copy link
Contributor Author

ping

@safareli
Copy link
Contributor Author

Is there any particular blocker for getting this in? if yes can we at least expose constructors from some Internal module?

@thomashoneyman
Copy link
Contributor

thomashoneyman commented Aug 21, 2019

@safareli I'm not familiar with the problem this addition is solving, nor of how to judge whether it's correct. Not because I don't think this is sensible, but simply because I'm not a heavy FreeT user :) Do you mind sharing a little more detail about what this is meant to accomplish?

Also, I'd appreciate hearing about why / whether a test case makes sense for this addition (where could it possibly go wrong? maybe a FreeT to Aff or Effect with something which would blow the stack?)

@safareli
Copy link
Contributor Author

In haskell there is type class MMonad which represents:

A monad in the category of monads, using lift from MonadTrans as the analog of return and embed as the analog of (=<<):

embed :: MMonad t => Monad n => (forall a. m a -> t n a) -> t m b -> t n b is main function of interest for us.

Let's look at it's signature, aligned with signature of bind, substFree and substFreeT:

bind       :: forall m a      (          a   -> m         b) -> m         a -> m         b
embed      :: forall m n b t. (forall a. m a -> t     n   a) -> t     m   b -> t     n   b
substFree  :: forall m n b    (forall a. m a -> Free  n   a) -> Free  m   b -> Free  n   b
substFreeT :: forall m n b g. (forall a. m a -> FreeT n g a) -> FreeT m g b -> FreeT n g b```

substFreeT has similar usage as substFree and bind have, they allow you to "graft" trees at leaves.

Here is example of it's usage:
https://github.com/blinky3713/purescript-coroutine-transducers/pull/1/files#diff-950dba9d55bad1315168b59150f435f4R114

Note: interpret is like map where substFreeT is like bind.

@garyb
Copy link
Member

garyb commented Aug 21, 2019

There's a corresponding substFree for the non-T Free too.

@thomashoneyman thomashoneyman self-assigned this Aug 21, 2019
@safareli
Copy link
Contributor Author

yes

Adds FreeT version of substFree :: forall f g. (f ~> Free g) -> Free f ~> Free g

@thomashoneyman
Copy link
Contributor

Ok! Sounds good, thank you @safareli.

@thomashoneyman thomashoneyman merged commit c85451a into purescript-contrib:master Aug 21, 2019
@thomashoneyman
Copy link
Contributor

Released as v4.1.0

@safareli safareli deleted the patch-1 branch August 22, 2019 10:34
@safareli
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants