mutable records

Manuel M T Chakravarty chak@cse.unsw.edu.au
Tue, 03 Sep 2002 18:37:18 +1000 (EST)


"Scott J." <jscott@planetinternet.be> wrote,

> Is it possible to define  oject types in Haskell and what does one propose to do it?

Depends on what you mean by object types.  You can surely
define a record with funcions dubbing as methods and
non-functional values dubbing as object data.

> Is it possible to define parts of a record  with the help of the ST s monad mutable during the whole program? (As is possible in Ocamel)?

Just make the fields that you want to update be values of
`STRef s a'.  (You can also do the same with the IO monad
and `IORef's.)

Having said this, there are not that many situations where
you need to do this (and in consequence ST-monadify your
program).  Purely functional updates (using the record
syntax) where the system effectively copies the whole record
(not all data in it, just the references to that data) is
perfectly suitable in most cases.  If you are concerned
about efficiency first profile the code to see whether the
performance bottleneck is really where you think it is.

Cheers,
Manuel