hapistrano icon indicating copy to clipboard operation
hapistrano copied to clipboard

Use deriving strategies for Hapistrano's Monad

Open ibarrae opened this issue 2 years ago • 4 comments

As it is now, we Hapistrano is using the following monad stack: https://github.com/stackbuilders/hapistrano/blob/f3fbe9a34cde5c645cbb4d51a48647a80ea00b92/src/System/Hapistrano/Types.hs#L49

Using deriving strategies The monad could be implemented like the following:

newtype Hapistrano (a :: Type) = Hapistrano {unHapistrano :: Config -> IO a}
  deriving (Functor, Applicaitve, Monad, MonadThrow) via (ReaderT Config IO)

That could remove the current monad stack and also lift operations between them, exceptions could be caught at top level during the execution of commands and could simplify the code a bit.

For backward compatibility, we might use CPP as well to keep the monad stack or choose the new monad as well.

Let me know how does this sound :smile:

ibarrae avatar Feb 18 '22 17:02 ibarrae

This looks doable. I have a question regarding the usage of MonadCatch here (which would need to be added to the instances of the newtype): to preserve the ability to handle the current error we have, i.e. the pair (Failure, Maybe Release), we would define something like this:

newtype FailureException = FailureException { unFailureEx :: (Failure, Maybe Release) }
  deriving (Show, Typeable)

instance Exception FailureException

is that right? In that case, I think the refactor could be quite easy to carry out.

DavidMazarro avatar Feb 21 '22 10:02 DavidMazarro

Yeah, I think that would do. You could also use anyclass as well for the instance of Exception.

newtype FailureException = FailureException { unFailureEx :: (Failure, Maybe Release) }
  deriving (Show, Typeable)
  deriving anyclass Exception

ibarrae avatar Feb 21 '22 14:02 ibarrae

Hey @ibarrae Would you mind if I pick this one? I haven't touch this new type of deriving and I'd love to learn more about it.

CristhianMotoche avatar Mar 22 '22 22:03 CristhianMotoche

For sure @CristhianMotoche :rocket:

ibarrae avatar Mar 22 '22 23:03 ibarrae

Solved in #204

CristhianMotoche avatar Sep 27 '22 21:09 CristhianMotoche