morphismtech / squeal

Squeal, a deep embedding of SQL in Haskell
362 stars 32 forks source link

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

Open MangoIV opened 1 year ago

MangoIV commented 1 year ago

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

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

echatav commented 1 year ago

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

echatav commented 1 year ago

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

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

echatav commented 1 year ago

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