int-index / ether

Monad Transformers and Classes
https://int-index.github.io/ether/
BSD 3-Clause "New" or "Revised" License
78 stars 7 forks source link

Add instances for MonadBaseControl and others #4

Closed gittywithexcitement closed 9 years ago

gittywithexcitement commented 9 years ago

Today I found myself needing StateT to have an instance for MonadBaseControl and related type classes.

The instance definitions are boilerplate and easily defined.

instance MonadTransControl (Ether.StateT tag s) where
    type StT (Ether.StateT tag s) a = (a, s)
    liftWith f = Ether.stateT (Proxy :: Proxy tag) $ \s ->
                   liftM (\x -> (x, s))
                         (f $ \t -> Ether.runStateT (Proxy :: Proxy tag) t s)
    restoreT = Ether.stateT (Proxy :: Proxy tag) . const

instance (MonadBase b m) => MonadBase b (Ether.StateT tag s m) where
  liftBase = liftBaseDefault

instance (MonadBaseControl b m) => MonadBaseControl b (Ether.StateT tag s m) where
  type StM (Ether.StateT tag s m) a = ComposeSt (Ether.StateT tag s) m a
  liftBaseWith = defaultLiftBaseWith
  restoreM     = defaultRestoreM

If you're not averse, it would be nice to have these instances for all of the Control.Monad.Trans.Ether.* classes. I'm willing to make a PR and create the other instances.

int-index commented 9 years ago

I defined MonadTransControl and MFunctor instances in another branch. See here. I will merge this branch when I figure out a better design for my transformers-lift package.

For now you'll have to use orphan instances.

gittywithexcitement commented 9 years ago

Ok. Let me know how it goes.

int-index commented 9 years ago

MonadBase, MonadControl and MonadBaseControl instances are now in the master branch.

int-index commented 9 years ago

@gittywithexcitement Please confirm that this indeed fixes your issue.

gittywithexcitement commented 9 years ago

@int-index yes, it works for me. Thank you!