I'm in a monad transformer with IO and I'd like to define my own instance for Failure.
Because Failure already defines instances for IO and for MonadTrans, I cannot even build my own overlapping instance.
As far as I know, I have four options left:
Do you know any other option? What do you think?
A newtype
wrapper is the standard approach to such a problem. The GeneralizedNewtypeDeriving
extension makes optionally deriving instances from the wrapped monad a breeze.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- | Your custom monad transformer
newtype YourMonadT e m r =
YourMonadT (EitherT e m r)
-- Easily derive the instances using the GeneralizedNewtypeDeriving
deriving (Functor, Applicative, Monad, MonadIO)
instance Failure e (YourMonadT e m) where
failure = error "TODO: implement me however you want"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With