Proposal: Expose Coercions for unboxed arrays

David Feuer david.feuer at gmail.com
Mon Dec 5 19:18:05 UTC 2016


As discussed in [1], we now have

type role Array nominal representational
type role IOArray nominal representational
type role UArray nominal nominal
type role IOUArray nominal nominal
type role StorableArray nominal nominal
type role STArray nominal nominal representational
type role STUArray nominal nominal nominal

There are good reasons for these, as described in the ticket, but in
some particular cases, they're overkill. It might be nice to expose
the representational equivalence locally, with the understanding that
the user has to ensure that the Ix, Storable, etc., instances are
compatible. I think the place for these is likely Data.Array.Unsafe,
although they'd need to be defined in GHC.Arr. For boxed arrays, it's
sufficient to expose a Coercion between partially applied
constructors. For unboxed arrays, such a coercion doesn't do much
(because the element type has a nominal role), so I think only
Coercions between the fully-applied constructors are really useful for
those. For STArray and STUArray, I don't *think* we want to expose a
coercion to change the state thread type; anyone fussing at such a low
level is probably importing GHC.Arr anyway.

arrayCoercion :: Coercible i j => Coercion (Array i) (Array j)
ioarrayCoercion :: ...

uarrayCoercion :: (Coercible i j, Coercible a b) => Coercion (UArray i
a) (UArray j b)
iouarrayCoercion :: ...
storablearrayCoercion :: ...

starrayCoercion :: Coercible i j => Coercion (STArray s i) (STArray s j)
stuarrayCoercion :: (Coercible i j, Coercible a b) => Coercion
(STUArray s i a) (STUArray s j b)

[1] https://ghc.haskell.org/trac/ghc/ticket/9220


More information about the Libraries mailing list