Fast Mutable arrays and a general question about IO

Ron de Bruijn rondebruijn@yahoo.com
Sat, 3 May 2003 04:37:01 -0700 (PDT)


I am still stuck with the problem of creating an
IOArray. I have tried the following:

import Data.Ix
import Data.Array.MArray
import Monad
import IO
import Data.Array.IO

test=newArray (0,1) IOArray

But this doesn't work because the dataconstructor is
not in scope, although I have imported all imaginable
modules.

Then I tried:
test=newArray (0,1) Lesson

GHC told me I needed to create an instance of MArray
with it's type, but I had no idea of how to do such
thing.

So I went experimenting with type classes when I
encountered something very strange.

data Lesson=Lesson String Int Int String String

instance Show Lesson  where
show (Lesson s1 i1 i2 s2 s3) = show s1

Why does above instance of Show works with Hugs, but
not with GHC 5.04.2 (see error below)?

{-
Compiling Test             ( test.hs, interpreted )

test.hs:38:
    Ambiguous occurrence `show'
    It could refer to either `Test.show', defined at
test.hs:38
                          or `GHC.Show.show', imported
from Prelude at test.hs:1

Failed, modules loaded: none.

I now have two pieces of information, at least I think
so: I need some instance of my an MArray of my
datatype Lesson as an elementtype.
And I need some way of integrating the IOArray in that
definition. Although this statement is completely easy
for an experimented Haskellprogrammer, but
it isn't for me.

Can somebody please help me with some concrete stuff
(I do understand it's better to do it yourself, but I
really don't know how to get any further)?

Greets Ron

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