EvEff icon indicating copy to clipboard operation
EvEff copied to clipboard

Add monad effects

Open noughtmare opened this issue 3 years ago • 2 comments

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

noughtmare avatar Mar 21 '21 11:03 noughtmare

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

xnning avatar Jul 16 '21 17:07 xnning

@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.

noughtmare avatar Jul 16 '21 17:07 noughtmare