drama icon indicating copy to clipboard operation
drama copied to clipboard

Instances for `exceptions` classes

Open NicolasT opened this issue 2 years ago • 5 comments

Since the Actor monad is basically a ReaderT, do you think it'd be possible to add instances for exception's MonadThrow, MonadCatch and MonadMask? Of course, exception handling ought to be handled a bit different in an actor-style architecture, but being able to use bracket (and similar) to manage resources is quite important nonetheless.

As an example, currently I don't believe it's possible to write an actor which uses network-simple's listen and accept, to then cast any new client socket to some manager actor.

NicolasT avatar Feb 11 '23 19:02 NicolasT

My bad, using liftIO and withRunInIO, it is possible to use catch and whatnot, and hence achieve what I was after, but it feels a bit complicated v.s. having MonadCatch etc. available.

NicolasT avatar Feb 11 '23 20:02 NicolasT

I prefer to keep a minimal dependency footprint. The unliftio package handles most of the standard-library-ish combinators like bracket, catch, async, etc. And for libraries like network-simple, it's possible to define orphan Monad{Throw,Catch,Mask} instances for Actor via the underlying ReaderT.

Also, drama is mostly a toy/experimental library right now; there's lots of stuff which is missing or incorrect. I wouldn't use it for anything serious.

That said, I'll consider depending on exceptions in the future.

evanrelf avatar Feb 16 '23 00:02 evanrelf

Well, unliftio uses/depends on safe-exceptions, which pulls in exceptions anyway (it uses the very same Monad{Throw,Catch,Mask} classes), so there wouldn't really be an extra dependency, only an extra direct dependency :wink:

Sure, and orphan instance can be created (that's what I do right now), but I prefer to avoid those whenever possible.

NicolasT avatar Feb 16 '23 08:02 NicolasT

drama depends on unliftio-core (contains just the MonadUnliftIO type class), not unliftio (contains lots of standard library stuff).

evanrelf avatar Feb 16 '23 17:02 evanrelf

:facepalm:

NicolasT avatar Feb 16 '23 17:02 NicolasT