Partially lift with liftIO
I'm trying to do something that's probably impossible. I have a type that is an instance of MonadIO
. If you liftIO
an IO
action in a context where this type is the base monad of some transformer stack, it will work fine. So, what I'd like to be able to do is take a value that's already been lifted part-way (to my type) and lift it "the rest of the way" in one step.
I can do this in two ways. One is that my type can actually be trivially re-embedded into normal IO, so I can do this:
liftMore :: (MonadIO m) => MyType a -> m a
liftMore x = liftIO $ embedMyTypeInIO x
And this works. However, this also provides a way to fully escape from my type if used in context where just IO
is the base monad, which is undesirable.
I can also do this by building a new typeclass like MonadIO
that uses my type as a base, but then it needs to be instantiated for everything, which is very undesirable. I tried using a newtype wrapper to make every monad transformer an instance of such a class, but couldn't quite get it.
Any ideas on strategies I could try to accomplish this? (I'm willing to play with language extensions, but of course a solution that is Haskell98 is much preferrable).
链接地址: http://www.djcxy.com/p/66624.html上一篇: 我可以限制类型家庭吗?
下一篇: 升降机部分升降