Hi all,<br><br>I&#39;m trying to define a type synonym for 2D MArray instances. The goal is to keep the function signature simple and readable using type `Matrix` instead of something like `(Ix i, MArray a e m) =&gt; m (a i e)`.<br>
<br>After some &quot;read, guess, try, error&quot; cycles I came up with this:<br><br>&nbsp;&nbsp;&nbsp; type Matrix = forall m. forall a. forall i. forall n. (Ix i, MArray a n m, Num i, Num n) =&gt; m (a (i,i) n)<br><br>it requires option -XRank2Types to work. But then I can write my function as:<br>
<br>&nbsp;&nbsp;&nbsp; test :: Matrix<br>&nbsp;&nbsp;&nbsp; test = do { a &lt;- newArray ((0,0),(5,8)) 0; writeArray a (0,0) 1; return a }<br><br>Then I wanted to be able to give the Index and Value types in the type synonym but keep it flexible in terms of which MArray instance is used. I changed it to:<br>
<br>&nbsp;&nbsp;&nbsp; type Matrix i n = forall m. forall a. (MArray a n m) =&gt; m (a (i,i) n)<br><br>and the type signature of the test function becomes:<br><br>&nbsp;&nbsp;&nbsp; test :: Matrix Int Double<br><br>For this one I had to add an extra -XFlexibleContexts option to build it.<br>
<br>It works and I&#39;m quite happy with the look of my new function type signatures, but I&#39;m just wondering if I&#39;m doing something bad or if there is a cleaner/simpler way to define the same type synonym without requiring language extensions. What are the risks associated with using these two language extensions, non compatibility with other compilers or more?<br>
<br>Thanks,<br><br>Olivier.<br>