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

Newtyped Effect types with identical dictionaries don't benefit from MagicDo #3796

Open
LiamGoodacre opened this issue Feb 22, 2020 · 1 comment

Comments

@LiamGoodacre
Copy link
Member

Input

newtype E i = E (Effect i)
derive newtype instance functorE :: Functor E
derive newtype instance applyE :: Apply E
derive newtype instance applicativeE :: Applicative E
derive newtype instance bindE :: Bind E
derive newtype instance monadE :: Monad E
egE :: E Unit
egE = do
  E (log "abc")
  E (log "abc")
  E (log "abc")

Expected

var egE = function __do() {
    Effect_Console.log("abc")();
    Effect_Console.log("abc")();
    return Effect_Console.log("abc")();
};

Actual

var egE = Control_Bind.discard(Control_Bind.discardUnit)(bindE)(Effect_Console.log("abc"))(function () {
    return Control_Bind.discard(Control_Bind.discardUnit)(bindE)(Effect_Console.log("abc"))(function () {
        return Effect_Console.log("abc");
    });
});
@nwolverson
Copy link
Contributor

nwolverson commented Jun 21, 2022

The machinery around #3915 (and specifically the expander in the optimizer) should make this fairly straightforward, I accidentally implemented this for purerl when integrating that change.

Edit: Actually not quite so easy in general, this is almost free in the same module but requires some more information cross-module

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

2 participants