how to declare instances for typeclasses with functional dependencies? #119
-
i was trying to write a Megaparsec effect following the guide on Effectful.Dispatch.Dynamic and when it became time to write the typeclass it complained that e and s weren't uniquely determined by es which makes sense because it would need to look at the instance context to know that it is. the error i got is the following
basically how can i force it to accept my instance declaration given that i know it is safe? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Oh. Indeed, I forgot about this particular case. You can force GHC to ignore the coverage condition by using a trick, i.e. including the instance head in the context: instance forall e s es. (Ord e ,P.Stream s, Megaparsec e s :> es, MonadParsec e s (Eff es))=> MonadParsec e s (Eff es ) where For the record, I didn't think too much about potential consequences for this particular case, but it should work as expected. Also, you'll probably want to use effectful-plugin for good user experience with this effect. |
Beta Was this translation helpful? Give feedback.
Oh. Indeed, I forgot about this particular case.
You can force GHC to ignore the coverage condition by using a trick, i.e. including the instance head in the context:
For the record, I didn't think too much about potential consequences for this particular case, but it should work as expected.
Also, you'll probably want to use effectful-plugin for good user experience with this effect.