The problem is with functions like withTransaction or withConnection
that require a function (m a -> Aff (Either PGError a)), where m is the constrained monad.
AFAIK you must concretize the monad type to use it.
I ended up writing my own version of withTransaction
withTransaction_
∷ ∀ e m
. MonadError e m
⇒ (String → m Unit)
→ m ~> m
withTransaction_ execute action = do
execute "BEGIN TRANSACTION"
a ← action `catchError` \e → do
execute "ROLLBACK TRANSACTION"
throwError e
execute "COMMIT TRANSACTION"
pure a
And the specific version:
withTransaction ∷ ∀ m. MyMonad m ⇒ m ~> m
withTransaction = withTransaction_ myExecute
The problem is with functions like
withTransaction
orwithConnection
that require a function(m a -> Aff (Either PGError a))
, wherem
is the constrained monad.AFAIK you must concretize the monad type to use it.
I ended up writing my own version of
withTransaction
And the specific version: