purescript / purescript-refs Goto Github PK
View Code? Open in Web Editor NEWMutable value references
License: BSD 3-Clause "New" or "Revised" License
Mutable value references
License: BSD 3-Clause "New" or "Revised" License
I think it wouldn't be hard to do an Eq instance for Ref right? Would you be open to a pull request?
Preempted by purescript/purescript-st#4:
modifySTRef :: forall a h r. STRef h a -> (a -> a) -> Eff (st :: ST h | r) a
modifyRef :: forall s r. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit
In particular the current behavior of modifyRef'
strangely returns an arbitrary value not what's stored.
I think it would be good to export uncurried variants of the operations for cases where we want to forgo the overhead of currying.
I've bumped into a few cases where it would be really handy to be able to construct a Ref
outside of Eff
- it seems to me that reading and writing a ref are definitely effectful, but creating one isn't necessarily so. Thoughts?
Quick question on the type of new
. Why does it have the type new :: forall s. s -> Effect (Ref s)
instead of new :: forall s. s -> Ref s
? I see no effects happening in the code.
I am using purescript for a canvas-based web app and don't need any fancy UI library. I end up with a lean, global application state and deal with events quite bare-footed.
I find myself writing
app <- read refAppState
flip write refAppState $
app { foo = newFoo
, bar = app.bar + 1
}
quite a lot.
If you don't object, I'll come up with a pull request soon to allow to write the above via a monad for effectfull, global state:
foo .= newFoo
bar += 1
I miss the lenses :)
Also, maybe you have a suggestion for the module name.
How about Effect.Ref.Monad
? Alternatively Control.Monad.State.Global
.
Mimicing Lens
:
(.=) = writeRef
(%=) = modifyRef
(%%=) = modifyRef`
In practice looks like:
nextEvent counter payload = do
count <- getRef counter
counter %= (_ + 1)
pure (Event (payload {id = count}))
Just wondered if it might be generally useful?
The function passed to newWithSelf
should not read or write to the reference it's passed, though it may create closures that will eventually do so. This restriction is not documented.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.