I would like to create a data structure that uses an unboxed array as
one of its components. I would like the data structure to be
parameterized over the type of the elements of the array. Further, I'd
like to build the array using runSTUArray. I can't make the code work
though. My naive approach:

  data Ring a = Ring (UArray Int a)

and the code to make the array:

  makeArray :: [a] -> Ring a
  makeArray ls = Ring (ST.runSTUArray (ST.newListArray (0, length ls - 1) ls))

But that doesn't work. I get from GHC (6.8.1):

  Could not deduce (MArray (STUArray s) a (ST s)) from the context ()
    arising from a use of `newListArray'

I am pretty sure I need to constrain 'a' to primitive types only, but
how? Can I do it in the data definition?

Thanks in advance for any help!

Justin
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to