Automatically recalculate results

Viewed 160

Basically, I want to be able to write some code like the following:

main = do
  x <- newVal (2 :: Int)
  y <- newVal (3 :: Int)
  z <- newFunc (x, y) (\(a,b) -> a * b) 
  r1 <- readVal z
  print r1 -- prints 6 (2 * 3)
  setVal x 5
  r2 <- readVal z
  print r2 -- prints 15 (5 * 3)

Could someone provide some sample code from scratch or from a library that would allow me to achieve something like the above?

3 Answers
Related