[Haskell-cafe] unboxed arrays restricted to simple types (Int, Float, ..)

Eugene Kirpichov ekirpichov at gmail.com
Wed Nov 11 07:34:50 EST 2009

You might also look at how Data Parallel Haskell implements its arrays.
IIRC, it implements an array of n-field records as n arrays. You can
easily do that with typeclasses and type families.

2009/11/11 Tillmann Vogt <Tillmann.Vogt at rwth-aachen.de>:
> Hi,
> I tried to use unboxed arrays for generating an antialiased texture. To make
> it easier to understand, here is the stripped down code that produces an
> error:
>>import Control.Monad.ST
>>import Data.Array.ST
>>import Data.Array.Unboxed
>>import Data.Word
>>type BitMask = UArray Int Word16 -- for determining the grey value of a
>> pixel
>>type Pixels = (Int, Int, T)
>>data T = N | B BitMask -- this does not work
>>-- type T = Int -- this works if int the next line N is replaced by ..lets
>> say 0
>>f = newArray (0,10) N :: (ST s (STUArray s Int T))
> http://hackage.haskell.org/packages/archive/array/
> shows that mutable/unboxed arrays only allow simple types:
> i.e.  MArray (STUArray s) Int32 (ST s)
> Isn't this ugly? Imagine this would be the case in C:
> struct stupidArrayElement{
>  int a;
>  int b; // not allowed!
> }
> stupidArrayElement s[10];
> Wouldn't it be nice to have something like: MArray (STUArray s) e (ST s)
> with e being a non-recursive data type (like data T = N | B Bitmask).
> My understanding of Haskell isn't deep enough to know if I have overlooked
> something or if the problem is solvable without a language extension. With a
> language extension I guess that it is not hard to find out if an abstract
> data type is non-recursive. Then this type should be serializable
> automatically.
> What do you think?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Eugene Kirpichov
Web IR developer, market.yandex.ru

More information about the Haskell-Cafe mailing list