{-# LANGUAGE DerivingVia #-} module M where import Control.Monad.State import Control.Monad.Except -- funnily, this is necessary for the `coerce` inherent in DerivingVia to be accepted import Data.Functor.Identity newtype M e s a = M (s -> Either e (a, s)) deriving (Functor, Applicative, Monad, MonadState s, MonadError e) via (StateT s (Except e))