1
votes

I have two monads that are very similar (they actually have the same name, but are not perfectly identical) and derive from the same class type. Unfortunately these monads are defined in different libraries and don't know about each other. When I try to use MonadB in LibraryA as a function context, I'm getting an error that it's expecting MonadA, understandably so. Is there any way to polymorphically use MonadB within LibraryA without linking the two libraries together, perhaps by using their general class type as a context instead?

1
monad is a collection of function.. i think you can not just substitute one code for another in binaries.. that would open all kinds of weird and security risks. - Ashish Negi
You should provide more details -- it's hard to guess here. - chi

1 Answers

3
votes

You can use the class type as your context, that way you'll be restricted to the common subset.

myFun :: forall m. MyClass m => m a

You can also add additional classes there, altough the MyClass will typically require Monad anyway.