Hello,<br><br>For testing purposes, I am trying to make an overlay to IO which carries a phantom type to ensure a context.<br>I define contexts using empty type classes :<br><br>class CtxFoo c<br>class CtxBar c<br><br>The overlay :<br>

<br>newtype MyIO c a = MyIO (IO a)<br><br>Then I define some methods that run only a specific context :<br><br>runFoo :: (CtxFoo c) =&gt; MyIO c a -&gt; IO a<br>runFoo (MyIO x) = x<br><br>runBar :: (CtxBar c) =&gt; MyIO c a -&gt; IO a<br>

runBar (MyIO x) = x<br><br>And then an action that runs in context &#39;Foo&#39; :<br><br>someAction :: (CtxFoo c) =&gt; MyIO c ()<br>someAction = putStrLn &quot;FOO&quot;<br><br>Then I run it :<br><br>main = runFoo someAction<br>

<br>But obiously, GHC complains that my type &#39;c&#39; remains uninstantiated :<br><br>    Ambiguous type variable `c&#39; in the constraint:<br>      (CtxFoo c) arising from a use of `runFoo&#39;<br>    Probable fix: add a type signature that fixes these type variable(s)<br>

    In the expression: runFoo someAction<br>    In an equation for `main&#39;: main = runFoo someAction<br><br><br>Is there a way to deal with this ?<br>The interest of using type classes and not empty types to represent the contexts is that it stays simple, and that I can do that :<br>

<br>someAction2 :: (CtxFoo c, CtxBar c) =&gt; MyIO c ()<br>someAction2 = putStrLn &quot;FOO and BAR&quot;<br><br>... a function that can run in both contexts.<br>