evanrelf / drama

🎭 Actor library for Haskell
https://hackage.haskell.org/package/drama
BSD 3-Clause "New" or "Revised" License
30 stars 1 forks source link

Instances for `exceptions` classes #13

Open NicolasT opened 1 year ago

NicolasT commented 1 year ago

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 commented 1 year ago

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.

evanrelf commented 1 year ago

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.

NicolasT commented 1 year ago

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.

evanrelf commented 1 year ago

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

NicolasT commented 1 year ago

:facepalm: