Hi all,<br><br>I'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) => m (a i e)`.<br>
<br>After some "read, guess, try, error" cycles I came up with this:<br><br> type Matrix = forall m. forall a. forall i. forall n. (Ix i, MArray a n m, Num i, Num n) => m (a (i,i) n)<br><br>it requires option -XRank2Types to work. But then I can write my function as:<br>
<br> test :: Matrix<br> test = do { a <- 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> type Matrix i n = forall m. forall a. (MArray a n m) => m (a (i,i) n)<br><br>and the type signature of the test function becomes:<br><br> 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'm quite happy with the look of my new function type signatures, but I'm just wondering if I'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>