Fast Mutable arrays and a general question about IO

Glynn Clements glynn.clements@virgin.net
Sat, 3 May 2003 13:39:41 +0100


Ron de Bruijn wrote:

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

1. Initially it would be simpler to ignore MArray altogether, and just
use IOArray directly.

2. newArray (and newIOArray etc) is a monadic operation, so you have
to use do notation or >>=.

E.g.

module Main where

import IOExts

data Lesson = Lesson String Int Int String String
	deriving Show

main = do
	test <- newIOArray (0,1) (Lesson "" 0 0 "" "")
	...

-- 
Glynn Clements <glynn.clements@virgin.net>