I want to modify my state with a function that depends on the old state, but also introduces some randomness. My function f
looks like this:
f :: State -> Eff (random :: RANDOM) State
I guess my state should be pure, and I had no idea how to get rid off Eff
, other than using unsafePerformEff
, so I did this:
eval :: Query ~> H.ComponentDSL State Query g
eval (Tick next) = do
H.modify (unsafePerformEff <<< f)
pure next
This works, but there has to be another, more safe way. I already added the random effect to my main function:
main :: Eff (H.HalogenEffects (random :: RANDOM)) Unit
But how should eval
look like? Maybe modify
does not work here, and there is another way to update state?
Purescript Halogen, side effect (random number) does not work for me, since f
depends on the old state.
get
andset
, but I still get type errors. – stholzm