Random access times

Ron de Bruijn rondebruijn@yahoo.com
Sat, 10 May 2003 02:03:27 -0700 (PDT)

I finally succeeded in doing your little exercise :),
except for the newArray_. 
I get the following error:

Compiling Try              ( try.hs, interpreted )

    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
    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.

newArray_ bound= do

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

Greets Ron

Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.