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 )

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

Greets Ron



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