Type roles for UArray?

Reid Barton rwbarton at gmail.com
Tue Mar 24 14:15:30 UTC 2015

On Tue, Mar 24, 2015 at 9:57 AM, wren romano <winterkoninkje at gmail.com>

> So I was working on porting my libraries to work for GHC 7.10 and I
> ran into a snag. Unlike the concrete type Data.Array.Array,  the
> concrete type Data.Array.Unboxed.UArray is defined as being nominal in
> the second type argument— is this a bug?

No, see https://ghc.haskell.org/trac/ghc/ticket/9220.

> If not, then why must it be nominal? Shouldn't (UArray a New) and
> (UArray a Old) have the same representation in memory? Using
> unsafeCoerce has always been safe here in the past...

It wasn't and isn't necessarily safe (though in some cases it is safe). The
IArray instances for Old and New could be unrelated (for example, they
could use a different amount of space per element). Knowing that Old and
New are related by a coercion means that the heap representation of actual
values of types Old and New are the same, but that says nothing about how
these values are stored in an unboxed array.

Reid Barton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150324/42a491b4/attachment.html>

More information about the Libraries mailing list