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

Free with flipped type parameters is also a monad? #33

Open
safareli opened this issue Nov 9, 2016 · 1 comment
Open

Free with flipped type parameters is also a monad? #33

safareli opened this issue Nov 9, 2016 · 1 comment
Labels

Comments

@safareli
Copy link
Owner

safareli commented Nov 9, 2016

//data FlipFree a i = FlipFree { flip :: Free i a }
const FlipFree = daggy.tagged('flip')

// same as `hoist`
// :: FlipFree z a ~> (a -> b) -> FlipFree z b
// FlipFree.prototype.map - TODO derive

// same as `???`
// :: FlipFree z (a -> b) -> FlipFree z a -> FlipFree z b
// FlipFree.prototype.ap - TODO derive


// ap                :: (Monad m) => m (a -> b) -> m a -> m b
// ap m1 m2          = do { x1 <- m1; x2 <- m2; return (x1 x2) }


// this is same as `graft`
// :: FlipFree z a ~> (a -> FlipFree z b) -> FlipFree z b
FlipFree.prototype.chain = function(f) {
  return FlipFree(this.flip.foldMap(v => f(v).flip, this.flip.constructor))
}
@safareli safareli added the idea label Nov 9, 2016
@safareli
Copy link
Owner Author

Free is MMonad where embed is graft
https://hackage.haskell.org/package/mmorph-1.0.9/docs/Control-Monad-Morph.html

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

No branches or pull requests

1 participant