Thanks for your proposal.<br><br>&gt; It is not clear if the class constraint is really needed.<br><br>Well &#39;IM&#39; means &#39;ImplementationMonad&#39;, so it wouldn&#39;t make much sense if an IM of an implementation wasn&#39;t also a monad. And since IM is the central monad of the library, a lot of functions will use IM.<br>

The methods will be spreaded over various classes. For instance the class IWindow :<br><br>class IWindow i where<br>    withinWindow :: Window -&gt; IM i Window a -&gt; IM i x a<br><br>So a method like &#39;cast&#39; shouldn&#39;t exist, since it would allow the user to switch the context freely. Methods like withinWindow will do that, but safely.<br>

<br><div class="gmail_quote">2011/3/3  <span dir="ltr">&lt;<a href="mailto:oleg@okmij.org">oleg@okmij.org</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div class="im"><br>
Yves Pare`s  wrote:<br>
&gt; I&#39;m working on a library which aims to be a generic interface for 2D<br>
&gt; rendering. To do that, one of my goals is to enable each implementation of<br>
&gt; this interface to run in its own monad (most of the time an overlay to IO),<br>
&gt; thus giving me the following class<br>
&gt;<br>
&gt; class (Monad (IM i x)) =&gt; Impl i x where<br>
&gt;     data IM i x :: * -&gt; *<br>
&gt;<br>
&gt; (where IM means Implementation Monad)<br>
&gt;<br>
</div><div class="im">&gt; I would like to write something like :<br>
&gt;<br>
</div><div class="im">&gt; class (forall x. Monad (IM i x)) =&gt; Impl i where<br>
&gt;     data IM i :: * -&gt; * -&gt; *<br>
<br>
</div>It is not clear if the class constraint is really needed. As an aside,<br>
a class constraint is perhaps a bit of mis-feature of type classes: it sure<br>
improves convenience by making signatures shorter. But it isn&#39;t really<br>
necessary. Perhaps there are other, better ways of achieving the<br>
convenience (the constraint alias proposal comes to mind).<br>
<br>
If we drop the class constraint, we can move Monad (IM i x) as the<br>
constraint on specific methods of the Impl class. The implicit uiniversal<br>
quantification on x is well allowed then. For example:<br>
<br>
&gt; class Impl (i :: * -&gt; *) where<br>
&gt;     data IM i :: * -&gt; * -&gt; *<br>
&gt;     foo :: Monad (IM i x) =&gt; Int -&gt; IM i x Int<br>
&gt;     bar :: Monad (IM i x) =&gt; IM i x Int -&gt; IM i x Bool<br>
&gt;     cast :: IM i x a -&gt; IM i y a<br>
&gt;<br>
&gt; data Window<br>
&gt;<br>
&gt; instance Impl IO where<br>
&gt;     newtype IM IO x a = IMIO (IO a)<br>
&gt;     foo = IMIO . return<br>
&gt;     bar (IMIO x) = IMIO (fmap (&gt; 42) x)<br>
&gt;     cast (IMIO x) = IMIO x<br>
&gt;<br>
&gt; test :: (Monad (IM i Window), Impl i) =&gt; IM i Window Int -&gt; IM i x Bool<br>
&gt; test = cast . bar<br>
<br>
Perhaps this isn&#39;t what you had in mind; I more elaborate example<br>
would help then.<br>
</blockquote></div><br>