Search code examples
haskellservant

"No instance for" trait that's already implemented


I'd like to use Servant's ClientM monad with finally:: MonadBaseControl IO m => m a -> m b -> m a, but am faced with error No instance for (MonadBaseControl IO ClientM).

Oddly, this exact instance appears to be defined already, be it from an internal module.

Do I need to explicitly import such instances somehow?


Solution

  • It works fine if, as Daniel said, you import the module that defines the desired instance:

    Prelude> import Control.Exception.Lifted
    Prelude Control.Exception.Lifted> import Servant.Client
    Prelude Control.Exception.Lifted Servant.Client> :set -XTypeApplications
    Prelude Control.Exception.Lifted Servant.Client> :type finally @ ClientM
    finally @ ClientM :: ClientM a -> ClientM b -> ClientM a