Hi all, 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)`.
After some "read, guess, try, error" cycles I came up with this: 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) it requires option -XRank2Types to work. But then I can write my function as: test :: Matrix test = do { a <- newArray ((0,0),(5,8)) 0; writeArray a (0,0) 1; return a } 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: type Matrix i n = forall m. forall a. (MArray a n m) => m (a (i,i) n) and the type signature of the test function becomes: test :: Matrix Int Double For this one I had to add an extra -XFlexibleContexts option to build it. 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? Thanks, Olivier.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe