Skip to content

Instantly share code, notes, and snippets.

@Pitometsu
Last active March 24, 2019 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pitometsu/5e79f7cb077da03184170815fb6b7f5a to your computer and use it in GitHub Desktop.
Save Pitometsu/5e79f7cb077da03184170815fb6b7f5a to your computer and use it in GitHub Desktop.
module type Subscriber = sig
module Message : sig
type t = ..
end
type msgs
val filter_message : msgs -> Message.t option
val callback : Message.t -> msgs list
end
module type Bus = sig
include Subscriber
val components : (module Subscriber) list
end
module Add (A : Subscriber) (B : Subscriber) : Bus with module Message = (struct (* Error: syntax error *)
type t = ..
type t += A.Message.t
type t += B.Message.t
end) =
struct
let components = (module A) :: [ (module B) ]
let filter_message = ident
let callback msg = A.callback (A.filter_message msg) @ B.callback (B.filter_message msg)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment