[Haskell-cafe] Unboxed array of product type -> product type of unboxed arrays

Scott Dillard sedillard at ucdavis.edu
Wed Jul 2 13:56:44 EDT 2008

On Wed, Jul 2, 2008 at 11:52 AM, Daniel Fischer <daniel.is.fischer at web.de>

> Perhaps
> class (Ix i) => UArrClass i e where ...
> would work?
class Ix i => UArrClass i e where
  data UArr i e
  unsafeAt_ :: UArr i e -> Int -> e

    ( IArray UArray e
    , IArray UArray f
    , Ix i
    ) => UArrClass i (e,f)
    newtype UArr i (e,f) = UArrPair (UArray i e) (UArray i f)
    unsafeAt_ (UArrPair ea fa) i = (unsafeAt ea i , unsafeAt fa i)

    ( IArray UArray e
    , IArray UArray f
    , UArrClass i (e,f)
    , Ix i
    ) => IArray UArr (e,f)
    unsafeAt = unsafeAt_

test1 :: UArr Int (Int,Int) -> (Int,Int)
test1 a = unsafeAt a 5   --this is line 77

    Ambiguous type variable `i' in the constraint:
      `Ix i' arising from a use of `unsafeAt' at Array.hs:77:10-21
    Probable fix: add a type signature that fixes these type variable(s)

I think the 'i' there is the one from the method context of IArray,

class IArray a e where
   unsafeAt :: Ix i => a i e -> Int -> e

But that 'i' does not escape to the class context, so I have no way to
address it. I think I need to leave it free, but I can't do that with my
associated type.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080702/1bcf698a/attachment.htm

More information about the Haskell-Cafe mailing list