squeal icon indicating copy to clipboard operation
squeal copied to clipboard

Would it be a good idea to write proper instances for `MonadResult`?

Open MangoIV opened this issue 2 years ago • 5 comments

Hi, currently the only instance for MonadResult is the catchall instance that then requires a MonadIO; would it be a good idea to instead write proper instances for all the usual Monad transformers to be able to write interpretations that are not necessarily impure without using {-# OVERLAPPING #-} pragmas on the MonadResult instance?

MangoIV avatar Nov 05 '23 11:11 MangoIV

Also what I don't quite understand is; if we disregard overlapping instances, we get exactly MonadIO, right, because for any Monad m we instantly discharge into MonadIO, except if we specify a MonadResult constraint on that m

MangoIV avatar Nov 05 '23 13:11 MangoIV

MonadResult is only needed to define safe Transactions. Otherwise you’re right, MonadIO would suffice alone. Users should not write MonadResult instances.

echatav avatar Nov 14 '23 23:11 echatav

You can imagine that MonadResult is a superclass of MonadIO.

class MonadResult m => MonadIO m

It’s not possible to do that but the catchall instance mostly accomplishes the same thing.

instance MonadIO m => MonadResult m

echatav avatar Nov 15 '23 02:11 echatav

perhaps I need to rephrase my issue here; currently, afaict, there's no way to escape from PQ but using IO; there's no way to actually interpret the SQL queries in any other way; what I want to do is interpret a subset of squeal queries in a pure way, there's no way of doing so currently, afaict, because of the MonadIO io => PQ ... io and the getRows :: ... io .. type signatures where the latter stems from the catchall instace of MonadResult

MangoIV avatar Nov 15 '23 16:11 MangoIV

I see. I’m afraid I didn’t anticipate such a need as reinterpreting PQ purely as libPQ is IO bound.

echatav avatar Nov 15 '23 23:11 echatav