haskell - Haskeline: Implementing `MonadException` instance for `ReaderT r (StateT s m)` stack -
this question has answer here:
- monadexception instance not deduced 1 answer
let's have following monad transformer stack (r
, s
left ()
simplicity),
newtype mymonad m = mm (readert () (statet () m a)
if want use base monad haskeline's inputt
, need system.console.haskeline.monadexception
instance. given apparent complexity of these instances, i'd prefer let compiler derive me generalizednewtypederiving
. specifically, expect following typecheck,
{-# language generalizednewtypederiving, standalonederiving, flexiblecontexts #-} import control.monad.state import control.monad.reader import control.monad.io.class import control.applicative import system.console.haskeline.monadexception newtype mymonad m = mm (readert () (statet () m) a) deriving (functor, applicative, monad, monadio) deriving instance (monadexception m) => monadexception (mymonad m)
yet sadly, gives me,
/home/bgamari/hi.hs:11:1: not deduce (monadexception (statet () m)) arising superclasses of instance declaration context (monadio (mymonad m), monadexception m) bound instance declaration @ /home/bgamari/hi.hs:11:1-66 possible fix: add instance declaration (monadexception (statet () m)) in instance declaration `monadexception (mymonad m)'
looking @ provided instances statet
, readert
,
instance monadexception m => monadexception (readert r m) instance monadexception m => monadexception (statet s m)
it seems reasonable expect compiler deduce statet
instance. expecting of cunning generalizednewtypederiving
? how 1 implement instance short of open-coding it?
there 2 versions of state monad: strict , lazy. import control.monad.state
brings in lazy version, instance of monadexception
seems strict version.
try import control.monad.state.strict
instead of import control.monad.state
.
Comments
Post a Comment