event.ml 752 B

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