Skip to content

Add monad effects#4

Open
noughtmare wants to merge 1 commit into
xnning:masterfrom
noughtmare:monad-effect
Open

Add monad effects#4
noughtmare wants to merge 1 commit into
xnning:masterfrom
noughtmare:monad-effect

Conversation

@noughtmare

@noughtmare noughtmare commented Mar 21, 2021

Copy link
Copy Markdown

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

xnning commented Jul 16, 2021

Copy link
Copy Markdown
Owner

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

@noughtmare

Copy link
Copy Markdown
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