[Haskell-cafe] When you don't want to restrict the type of array...
ch.howard at zoho.com
Fri Aug 12 05:12:29 UTC 2016
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?
My PGP public key ID is 0x340EA95A (pgp.mit.edu).
More information about the Haskell-Cafe