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 monad effects #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

noughtmare
Copy link

@noughtmare noughtmare commented Mar 21, 2021

Fixes #2

I'm happy to discuss any suggestions for improving this.

Also note that I've put my own name in the copyright field on line 4, I am not certain if that is the right thing to do.

Edit: And maybe we should have a more explicit constraint that the MEff should be the last one in the effect stack. Something like:

class Last h e where
    lastContext :: Context e -> Context (h :* ())

instance Last h (h :* ()) where
    lastContext = id

instance Last h e => Last h (h' :* e) where
    lastContext ctx = lastContext (ctail ctx)

-- I've chosen $ because it means end of a line in regular expressions.
type h :$? e = Last h e

@xnning
Copy link
Owner

xnning commented Jul 16, 2021

Thanks for the pull request! I will take a look during this weekend.

@noughtmare
Copy link
Author

@xnning I think this pull request is a bit outdated. Wrapping Ctl with IO like I do in #7 is in my opinion a much better and probably much more performant way to implement IO. The only problem perhaps is that the performance of non-IO code takes a small hit, but on the other hand it improves the correctness of code that uses the Local effect (see #6).

There are some different designs. For example, you could wrap Ctl with an arbitrary monad m then code that doesn't use Local or IO can use Identity for that m and code that only wants a Local effect could perhaps use ST and code that don't use either can use Identity. With Identity there should be no overhead over the current, but then you cannot use Local anymore.

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

Successfully merging this pull request may close these issues.

runEffIO :: Eff (IOEff) a -> IO a
2 participants