Closed garyb closed 3 years ago
I have never had a use for it. However I could see using it with a Global
region to have a record with mutable fields.
then it wouldn't be ST anymore either.
We could just make ST
an indexed monad.
If the only good way to use this is with a Global
region it should just work in Effect
instead, I know I would've had a use for this a couple of times recently where handling a record full of Ref
s was a little annoying.
Ouch, that’s embarrassing, I didn’t even notice that there’s no way to add fields to a mutable record with the ST interface 🙈 I opened https://github.com/purescript/purescript-record/pull/77 to remove Record.ST.run.
I don’t think we should make ST an indexed monad just to satisfy one use case which nobody seems interested in anyway. I think the use case of wanting to have a record where all the fields are mutable and performance is too much of a concern to just put the whole record in the Ref is probably too niche to deserve a spot in core, so my preference would be removing the whole module.
This may be a case of serious user-error problem here, but it seems to me that
Record.ST
is only useful in a very specific and probably not common situation: you can only use it to modify the values of existing fields in a record.This isn't a complaint about
thaw
being the only way to get anSTRecord
, I see that there's an unreleased addition of anew
- but actually this is kinda useless, since you can't do anything with anSTRecord h ()
aside fromfreeze
orrun
. You cannot use theST
interface to add or remove fields.Given that it only allows modification, at the expense of one copy (at a minimum, two if
freeze
is used rather thanrun
), it seems like this module may as well not exist - you can just modify an object with update syntax or by rebuilding it completely for the same cost.I don't think it's fixable either - I think it could be done as an indexed monad perhaps, tracking the row in/out of each operation as the indexed part, but then it wouldn't be
ST
anymore either.If I'm wrong here, apologies, can someone show me how you'd use this to build a record from scratch. :smile: