Good answer: No, what you hope to do is not really viable. You can write an instance that looks like it is doing what you want, it might have some GHC extensions, but it will not work the way you would like.
Unreasonable answer: Perhaps you can accomplish what you want using frightening metaprogramming at the type level, but this can get complicated. It really is not recommended unless you need this job for some reason.
Officially, instances cannot really depend on other instances, because the GHC only looks at the "instance head" when making decisions, and the class constraints are in the "context". To do something like a โclass type synonymโ here, you need to write something that looks like an instance of Monad for all possible types, which obviously doesn't make sense. You will overlap with other Monad instances that have their problems.
Among other things, I donโt think that such an instance will satisfy the completion check requirements to resolve the instance, so you will also need the UndecidableInstances extension, which means the ability to write instances that will send the GHC type checker to an infinite loop.
If you really want to go down this rabbit hole, check out the site a bit
CA McCann May 20 '10 at 8:16 p.m. 2010-05-20 20:16
source share