behavior.ml 520 B

12345678910111213141516171819
  1. open Base
  2. type 'a t = Source.set * (Source.State.t -> 'a)
  3. let empty : Source.set = Set.empty (module Source)
  4. let return x = empty, (fun _ -> x)
  5. let const = return
  6. let map (s, g) ~f = s, fun t -> f (g t)
  7. let map2 (s1, g1) (s2, g2) ~f = Set.union s1 s2, fun t -> f (g1 t) (g2 t)
  8. let both bx by = map2 bx by ~f:(fun x y -> (x, y))
  9. let ( >>| ) b f = map ~f b
  10. let of_source s = Source.singleton s, Source.State.get_exn s
  11. let time = of_source Source.time
  12. let dependencies (s, _) = Set.to_sequence s
  13. let sample (_, f) = f