First of all, the current standard for arrays is the vector package, array is pretty obsolete. Secondly, are you sure you want your functions to take both immutable and mutable arrays? You could just make them take immutable ones, and convert using (unsafe)freeze/thaw beforehand. Also, since you know that you'll only be storing Face and Vertex, you might as well make an Unbox (or Storable) instance for them and use Unboxed (or Storable) vectors.

Then you end up with:

import qualified Data.Vector.Unboxed as VU

data Surface = Surface { vertices :: VU.Vector Vertex, faces :: VU.Vector Face }

render :: Surface -> IO ()

etc.

On Fri, Aug 12, 2016 at 7:12 AM, Christopher Howard <ch.howard@zoho.com> wrote:
Hi. I recently learned how to use Haskell IArrays and MArrays, and they
are quite convenient. I find myself often using some type of MArray for
performance reasons, but also some IArray type for array data that is
static in a set of computations.

Then I started wanting to use arrays inside other kinds of data types,
and so quickly ran into the question: what do you do if you want a data
type to contain an array, but you don't know in advance what array type
you'll be working with (immutable vs. mutible, boxed vs. unboxed).

My exploration of this question led to discovering something called
GADTs, which allowed me to do definitions like so

data Surface a where
  ISurface :: IArray a e => (a Int Vertex) -> (a Int Face) -> Surface a
  MSurface :: MArray a e m => (a Int Vertex) -> (a Int Face) -> Surface a

Am I heading down the right track here, or is there some better approach?

--
https://qlfiles.net
My PGP public key ID is 0x340EA95A (pgp.mit.edu).

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.