Skip to content
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

Add retractT #61

Closed
ekmett opened this issue Apr 26, 2014 · 8 comments
Closed

Add retractT #61

ekmett opened this issue Apr 26, 2014 · 8 comments

Comments

@ekmett
Copy link
Owner

ekmett commented Apr 26, 2014

Pipes.Group has

concats :: Monad m => FreeT (Producer a m) m x -> Producer a m x

which could generalize to

retractT :: (MonadTrans t, Monad m) => FreeT (t m) m x -> t m x

Alternately we might work with a monad homomorphism instead.

@fizruk
Copy link
Collaborator

fizruk commented Apr 28, 2014

It is currently possible to define

retractT :: (Functor (t m), Monad (t m), MonadTrans t, Monad m) =>
    FreeT (t m) m a -> t m a
retractT = iterTM join

Would you like this implementation?

@ekmett
Copy link
Owner Author

ekmett commented Apr 28, 2014

That looks right.

@fizruk
Copy link
Collaborator

fizruk commented Apr 28, 2014

Hm. There appears to be also a different version:

retractM :: (Functor m, Monad m) => FreeT m m a -> m a
retractM = iterT join

With that

retractT = retractM . hoistFreeT lift

Alternatively

retractM = runIdentityT . retractT . transFreeT IdentityT

Though I think iterT* join would be a better implementation for retract*.

Would you like both retractM and retractT?

@ekmett
Copy link
Owner Author

ekmett commented Apr 28, 2014

I'd check to see which matches the semantics of concats from Pipes.Group, but I think that is (obviously) the former.

retractM is kinda boring though. I think just doing retractT might offer a path to reduce the amount of pipes-specific code that @Gabriel439 has to write. ;)

@Gabriella439
Copy link
Contributor

Oh wow, I didn't even realize there was an iterTM. I'm probably going to keep the pipes-group code the way it is just because it helps people understand how to write their own folds.

@torgeirsh
Copy link

Having both a more general function and the example of fold code would be great. Perhaps the current concats code could be moved to a comment or the tutorial, and then let concats = retractT just like maps = transFreeT?

@Gabriella439
Copy link
Contributor

Alright, that sounds good. I can include the current implementation as a comment alongside the retractT version.

@ekmett
Copy link
Owner Author

ekmett commented Mar 7, 2015

Added in patch b75fbf5

@ekmett ekmett closed this as completed in 1bdbb2c Mar 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants