title: Make UArray a Functor
body: <p>I want to treat <code>UArray</code> as instance of <code>Functor</code>. I want to write a numeric code, and I need to use something more efficient than <code>Array</code> to represent the state (says the profiler). I understand that I could write my code without using functors, but I think functors are a very valuable abstraction that I'd like to have.</p>
  
  <p>As-is this doesn't work, because <code>UArray</code> is only an instance of <code>IArray</code> for certain basic types such as <code>Int</code> or <code>Double</code>. I am contemplating two approaches to make it work nonetheless:</p>
  
  <ul>
  <li>Return an error (either implicitly or explicitly) if the result of <code>fmap</code> is not an instance of <code>IArray</code></li>
  <li>Define a "composite" type that is either based on <code>UArray</code> (if possible) or on <code>Array</code> (if not), akin to a C++ template specialization</li>
  </ul>
  
  <p>I've tried various approaches based on various GHC extensions (existential types, functional dependencies, generalized algebraic data types, multi-parameter type classes, undecidable instances), but I just can't make things work. I always arrive at a point where I need to promise the compiler that "yes, the result will be representable via <code>UArray</code>", but there's just no syntax for it.</p>
  
  <p>I've read various papers, tutorials, and documentation for the GHC extensions above in the hope to find an example that tells me how to do that. The closest I could find is <a href="https://wiki.haskell.org/GADTs_for_dummies" rel="nofollow">https://wiki.haskell.org/GADTs_for_dummies</a>, which defines a class <code>IsSimple</code> that is very close to what I probably need.</p>
  
  <p>Can you give me a pointer for how to get started?</p>