type Cell<'T>(initial: 'T) = let mutable value = initial let mutable listeners : (unit -> unit) list = [] member _.Value = value member _.Set v = value <- v for l in listeners do l() member _.Subscribe(callback: unit -> unit) = listeners <- callback :: listeners type RuleBuilder() = member _.Bind(cell: Cell<'T>, f: 'T -> unit) = f cell.Value cell.Subscribe(fun () -> f cell.Value) member _.Return(x) = x member _.Delay(f: unit -> unit) = f() member _.Zero() = () let rule = RuleBuilder() // Define some reactive cells. let a = Cell(3) let b = Cell(4) let sum = Cell(0) // Create a reactive rule that computes the sum of a and b. rule { let! va = a let! vb = b sum.Set (va + vb) } printfn "Initial sum: %d" sum.Value // Changing 'a' will automatically update the computed sum. a.Set 10 printfn "Updated sum: %d" sum.Value