How to create an unboxed array?

Ron de Bruijn rondebruijn@yahoo.com
Tue, 13 May 2003 11:03:58 -0700 (PDT)


I finally succeeded in creating the unsafeWrite and
unsafeRead functions, but the newArray_ function will
not work. 

I get the following error:

Compiling Try              ( try.hs, interpreted )

try.hs:37:
    Could not deduce (Num i)
        from the context (MArray IOUArray Foo IO,
                          HasBounds IOUArray,
                          Monad IO,
                          Ix i)
    Probable fix:
        Add (Num i) to the class or instance method
`newArray_'
    arising from use of `*' at try.hs:37
    In the first argument of `newArray_', namely
        `(fst (bound), (snd (bound)) * 2)'
    In a 'do' expression pattern binding:
        newArray_ (fst (bound), (snd (bound)) * 2)
Failed, modules loaded: none.
Prelude>

newArray_ bound= do
                    newArray_
(fst(bound),snd(bound)*2)

I don't really understand why I have to do something
with the Numclass. I think it is to be sure of the
fact that the the arguments given in the tuple are
indextypes of type Num, so the values can always be
multiplied using the * operator. How can I make this
work and why will it work the way you would say it
would work? 

And why can't I just put the types of the functions
just above the definition, just like I do with any
other function, is it just because of the fact this is
a method of a class? 

    newArray_::(MArray a e m, Ix i) => (i, i) -> m (a
i e)
    newArray_ bound= do
                       newArray_ (fst(bound),snd
bound))

And then yet another question: if I had another
datatype, like Foo String Int, then I just had to
create two different arrays, one of Int and one of
String, right? 

Greets Ron


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com