2021年3月5日星期五

Using STArray and ignore the return of modify in Purescript

I think I'm close to what I want, though I suspect I'm not understanding how thaw / TH Region works.

Here is what I'm trying to implement (at least roughly)

modifyPerIndex :: forall t a. Foldable t => t (Tuple Int (a -> a)) -> Array a -> Array a  modifyPerIndex foldableActions array = run do    mutableArray <- thaw array    foreach actions (\(Tuple index action) -> modify index action mutableArray)    pure $ freeze mutableArray      where        actions = fromFoldable foldableActions  

This is sort of how I imagine updateAtIndices works. I suppose I could write modifyPerIndex to use updateAtIndices by reading in the values, applying the (a -> a) and mapping the result into a list of Tuples to be sent to updateAtIndices.

I'm curious how to do it this way though.

In the code above modify returns ST h Boolean, which I'd like to change into ST h Unit. That's where I'm lost. I get that h here is a constraint put on mutable data to stop it from leaving run, what I don't understand is how to use that.

https://stackoverflow.com/questions/66502256/using-starray-and-ignore-the-return-of-modify-in-purescript March 06, 2021 at 12:07PM

没有评论:

发表评论