Related question - Is it safe to derive MonadThrow, MonadCatch, MonadBaseControl, MonadUnliftIO, etc? - where I had enabled, both - DeriveAnyClass
and GeneralizedNewtypeDeriving
to get the code to compile, but didn't bother looking at the ominous warnings. Now, that I am running my refactored code, it's throwing a runtime error:
No instance nor default method for class operation >>=
So, I removed DeriveAnyClass
and kept ONLY GeneralizedNewtypeDeriving
and have the following compile error:
{-# LANGUAGE DataKinds, GADTs, ScopedTypeVariables, TypeFamilies, AllowAmbiguousTypes, RankNTypes, StandaloneDeriving, UndecidableInstances #-}
newtype AuthM (fs :: [FeatureFlag]) auth m a =
AuthM (ReaderT (Auth auth) m a)
deriving (Functor, Applicative, Monad, MonadReader (Auth auth), MonadIO, MonadThrow, MonadCatch, MonadMask, MonadUnliftIO)
-- • Couldn't match representation of type ‘m (Control.Monad.IO.Unlift.UnliftIO
-- (AuthM fs auth m))’
-- with that of ‘m (Control.Monad.IO.Unlift.UnliftIO
-- (ReaderT (Auth auth) m))’
-- arising from the coercion of the method ‘Control.Monad.IO.Unlift.askUnliftIO’
-- from type ‘ReaderT
-- (Auth auth)
-- m
-- (Control.Monad.IO.Unlift.UnliftIO (ReaderT (Auth auth) m))’
-- to type ‘AuthM
-- fs auth m (Control.Monad.IO.Unlift.UnliftIO (AuthM fs auth m))’
-- NB: We cannot know what roles the parameters to ‘m’ have;
-- we must assume that the role is nominal
-- • When deriving the instance for (MonadUnliftIO (AuthM fs auth m))
-- |
-- 82 | deriving (Functor, Applicative, Monad, MonadReader (Auth auth), MonadIO, MonadThrow, MonadCatch, MonadMask, MonadUnliftIO)
-- | ^^^^^^^^^^^^^
Note: I realise that the first error about >>=
has got nothing to do with the error about MonadUnliftIO
. I have confirmed that there are no warnings about a missing >>=
, when DeriveAnyClass
is turned off.
I guess I need to write the instance for MonadUnliftIO
myself, because the compiler probably cannot figure this out in the presence of a newtype
AND a phantom type-variable. However, I just can't figure out how to define the askUnliftIO
for my type, given above.
Attempt 1 at minimal code snippet
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Try13 where
import Control.Monad.Reader
import UnliftIO
import Control.Monad.Catch
data Auth = Auth
newtype AuhM m a = AuthM (ReaderT Auth m a)
deriving(Functor, Applicative, Monad, MonadReader Auth, MonadIO, MonadThrow, MonadCatch, MonadMask, MonadUnliftIO)
-- • Couldn't match representation of type ‘m (UnliftIO (AuhM m))’
-- with that of ‘m (UnliftIO (ReaderT Auth m))’
-- arising from the coercion of the method ‘askUnliftIO’
-- from type ‘ReaderT Auth m (UnliftIO (ReaderT Auth m))’
-- to type ‘AuhM m (UnliftIO (AuhM m))’
-- NB: We cannot know what roles the parameters to ‘m’ have;
-- we must assume that the role is nominal
-- • When deriving the instance for (MonadUnliftIO (AuhM m))
-- |
-- 12 | deriving(Functor, Applicative, Monad, MonadReader Auth, MonadIO, MonadThrow, MonadCatch, MonadMask, MonadUnliftIO)
-- | ^^^^^^^^^^^^^
--
Auth
andFeatureFlag
, or simplify this code to the minimal part that reproduces this issue? Right now it's impossible to easily reproduce the error you're getting, and I'm sure you could cut out a few irrelevant parts. – CuspidorAuhM
vsAuthM
? – Alcove