Record of STRefs better than STRef to a Record?

Hi all, If I use an STRef to a record, will a new record be created each time I want to update a single field? Or can I expect GHC to optimize it and have the field of the record updated in place? Right now I'm using a record of STRefs, like: data E s = E{ refi :: STRef s Int, refc :: STRef s Char } but it can get a little messy, since thread s propagates to every datatype that uses the record type in it's definition. Thanks, J.A.

G'day all. On Wed, Nov 13, 2002 at 04:05:42AM +0000, Jorge Adriano wrote:
If I use an STRef to a record, will a new record be created each time I want to update a single field?
Basically, yes.
Right now I'm using a record of STRefs, like: data E s = E{ refi :: STRef s Int, refc :: STRef s Char }
but it can get a little messy, since thread s propagates to every datatype that uses the record type in it's definition.
You could always use IORefs, if you don't mind having the IO monad threaded through. Cheers, Andrew Bromage

G'day all.
If I use an STRef to a record, will a new record be created each time I want to update a single field? Basically, yes.
Ok.
Right now I'm using a record of STRefs, like: data E s = E{ refi :: STRef s Int, refc :: STRef s Char }
You could always use IORefs, if you don't mind having the IO monad threaded through.
I'm using the Lazy version of ST with a monadic version of iterate to return an infinite list of values. Can't do that with IO... Thanks, J.A.
participants (2)
-
Andrew J Bromage
-
Jorge Adriano