event.ml 906 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. open Base
  2. open Math
  3. type event =
  4. | Click of Pos.t
  5. and t = event
  6. let equal (Click p1) (Click p2) = Pos.equal p1 p2
  7. let to_string = function
  8. | Click p -> Printf.sprintf "Click(%s)" (Pos.to_string p)
  9. type handler =
  10. event -> (Source.value -> Source.value) Source.map
  11. let handler_compose (f : handler) (g : handler) : handler =
  12. fun ev ->
  13. Map.merge_skewed (f ev) (g ev)
  14. ~combine:(fun ~key:_ f' g' x -> f' (g' x))
  15. module Id : sig
  16. include Identifiable.S
  17. val gen : unit -> t
  18. module Private : sig
  19. val next_id : diff:int -> t
  20. end
  21. end = struct
  22. include (Int : Identifiable.S with type t = int)
  23. let next = ref 0
  24. let gen () = let v = !next in Int.incr next ; v
  25. let to_string v = Printf.sprintf "<id:%d>" v
  26. module Private = struct
  27. let next_id ~diff = !next + diff
  28. end
  29. end
  30. type 'a map = (Id.t, 'a, Id.comparator_witness) Map.t
  31. let empty_map : _ map = Map.empty (module Id)