Mutant state in Purescript

I am just starting to learn Purescript, so I hope this is not a dumb question.

Suppose we have an object

a = {x:1,y:2}

an we want to change x to 2. As far as I can see, if we use the ST monad, we will have to copy the whole object to change the value. If the source object is large, it will be very inefficient. What is the correct way to modify objects?

+4
source share
1 answer

Monad STis a great approach, but depending on your use case, there may or may not be standard library functions for this.

Data.StrMap purescript-maps , , , Data.StrMap.ST .

, ST FFI. . - ,

setFoo :: forall r a h eff. STRef h { foo :: a | r } -> a -> Eff (st :: ST h | eff) Unit

. . , Data.StrMap: , .

+6

Source: https://habr.com/ru/post/1608704/


All Articles