Re: [Caml-list] a push style event combinator
(2011/09/15 23:45), Philippe Veber wrote: Thank you for releasing your library, it looks really interesting ! Thank you for your reply. How would you compare it with react (http://erratique.ch/software/react) which, AFAIU, can be used for similar purposes ? At least I can see there is no notion of signal (continuous function of time) in PEC (or maybe signals can be emulated somehow ?). Also could you comment on the 'no memory leaks' feature ? Yes, both the react and PEC can be used for similar purpose. But there are some different points between the two libraries. - PEC is "subscribe" centered. If you leave a event alone without subscribing, no actions will be occurred even if you send data to the event. The react library's system always runs update cycle at sending data to events. - Instead of signal, PEC have "value" function. "value" function attaches a event and returns a reference cell which contains latest occurrence data of the event. I think it's enough because signal is only terminal point of reactive events. - PEC's inside representation of event is not dependency graph but just nested variants. Let me assume a event A depends on other event B. In case of using dependency graph, event B has pointer of event A. This caused difficulty about memory leaks because there is no good timing to free the event A. PEC's event is just a nested variants. It means that event A has pointer of event B. So the event A will be garbage-collected automatically when the reference to the event A from application layer disappeared. That is the reason why "no memory leaks". Regards, ogasawara cheers, Philippe. 2011/9/15 Satoshi Ogasawara mailto:ogasaw...@itpl.co.jp>> Hello, I'd like to announce the release of PEC, a push style event combinator. PEC : https://github.com/osiire/Pec This small module(about 350 LOC) provides - a composable event. - map, choose, never, join and several useful functions. - immediate reactions corresponds sending data to events. - no memory leaks. I think PEC is useful to write event driven systems. The signature is as follows. type 'a event (** [make ()] makes a new event and sender function.*) val make : unit -> 'a event * ('a -> unit) val map : ('a -> 'b) -> 'a event -> 'b event (** [choose l] is a event which will be raised when one of specified events occurred. *) val choose : 'a event list -> 'a event val never : 'a event (** [join ee] is a event which will be raised when a inner event occurred. "Inner event" is a event comes from outer event [ee]. *) val join : 'a event event -> 'a event (** [bind e f] is [join (map f e)] *) val bind : 'a event -> ('a -> 'b event) -> 'b event val scan : ('a -> 'b -> 'a) -> 'a -> 'b event -> 'a event val filter : ('a -> bool) -> 'a event -> 'a event val filter_map : ('a -> 'b option) -> 'a event -> 'b event val zip : 'a event -> 'b event -> ('a * 'b) event val take_while : ('a -> bool) -> 'a event -> 'a event val take_while_in : ('a -> bool) -> 'a event -> 'a event val take_n : int -> 'a event -> 'a event val once : 'a event -> 'a event val drop_while : ('a -> bool) -> 'a event -> 'a event val drop_n : int -> 'a event -> 'a event val delay : int -> 'a event -> 'a event val pairwise : 'a event -> ('a * 'a) event (** [subscribe f e] attaches the [f] to the specified event. The [f] will be called when the [e] will occurred. *) val subscribe : ('a -> unit) -> 'a event -> unit (** [value e] returns a reference cell which store a latest value *) val value : 'a -> 'a event -> 'a ref (** [run ()] runs PEC event system and returns a number of queuing size of sended data. *) val run : unit -> int e.g. Using PEC, you can write a drag event from mouse events like this. let (+>) f g = g f (* E is PEC module *) let dragging mouse_down mouse_up mouse_move = E.bind mouse_down (fun dloc -> E.choose [ E.map (fun uloc -> `Drop (dloc, uloc)) mouse_up; E.map (fun mloc -> `Drag (dloc, mloc)) mouse_move; ] +> E.take_while_in (function `Drop _ -> false | _ -> true)) Regards, ogasawara -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
Re: [Caml-list] a push style event combinator
Thank you for releasing your library, it looks really interesting ! How would you compare it with react (http://erratique.ch/software/react) which, AFAIU, can be used for similar purposes ? At least I can see there is no notion of signal (continuous function of time) in PEC (or maybe signals can be emulated somehow ?). Also could you comment on the 'no memory leaks' feature ? cheers, Philippe. 2011/9/15 Satoshi Ogasawara > Hello, > > I'd like to announce the release of PEC, a push style event combinator. > > PEC : https://github.com/osiire/Pec > > This small module(about 350 LOC) provides > > - a composable event. > - map, choose, never, join and several useful functions. > - immediate reactions corresponds sending data to events. > - no memory leaks. > > I think PEC is useful to write event driven systems. The signature is as > follows. > > type 'a event > > (** [make ()] makes a new event and sender function.*) > val make : unit -> 'a event * ('a -> unit) > val map : ('a -> 'b) -> 'a event -> 'b event > > (** [choose l] is a event which will be raised when one of specified events > occurred. *) > val choose : 'a event list -> 'a event > val never : 'a event > (** [join ee] is a event which will be raised when a inner event occurred. >"Inner event" is a event comes from outer event [ee]. *) > val join : 'a event event -> 'a event > (** [bind e f] is [join (map f e)] *) > val bind : 'a event -> ('a -> 'b event) -> 'b event > val scan : ('a -> 'b -> 'a) -> 'a -> 'b event -> 'a event > val filter : ('a -> bool) -> 'a event -> 'a event > val filter_map : ('a -> 'b option) -> 'a event -> 'b event > val zip : 'a event -> 'b event -> ('a * 'b) event > val take_while : ('a -> bool) -> 'a event -> 'a event > val take_while_in : ('a -> bool) -> 'a event -> 'a event > val take_n : int -> 'a event -> 'a event > val once : 'a event -> 'a event > val drop_while : ('a -> bool) -> 'a event -> 'a event > val drop_n : int -> 'a event -> 'a event > val delay : int -> 'a event -> 'a event > val pairwise : 'a event -> ('a * 'a) event > > (** [subscribe f e] attaches the [f] to the specified event. >The [f] will be called when the [e] will occurred. *) > val subscribe : ('a -> unit) -> 'a event -> unit > > (** [value e] returns a reference cell which store a latest value *) > val value : 'a -> 'a event -> 'a ref > > (** [run ()] runs PEC event system and returns a number of queuing size of > sended data. *) > val run : unit -> int > > > e.g. > Using PEC, you can write a drag event from mouse events like this. > > let (+>) f g = g f > (* E is PEC module *) > let dragging mouse_down mouse_up mouse_move = > E.bind mouse_down (fun dloc -> E.choose [ >E.map (fun uloc -> `Drop (dloc, uloc)) mouse_up; >E.map (fun mloc -> `Drag (dloc, mloc)) mouse_move; > ] > +> E.take_while_in (function `Drop _ -> false | _ -> true)) > > > Regards, > ogasawara > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs
[Caml-list] a push style event combinator
Hello, I'd like to announce the release of PEC, a push style event combinator. PEC : https://github.com/osiire/Pec This small module(about 350 LOC) provides - a composable event. - map, choose, never, join and several useful functions. - immediate reactions corresponds sending data to events. - no memory leaks. I think PEC is useful to write event driven systems. The signature is as follows. type 'a event (** [make ()] makes a new event and sender function.*) val make : unit -> 'a event * ('a -> unit) val map : ('a -> 'b) -> 'a event -> 'b event (** [choose l] is a event which will be raised when one of specified events occurred. *) val choose : 'a event list -> 'a event val never : 'a event (** [join ee] is a event which will be raised when a inner event occurred. "Inner event" is a event comes from outer event [ee]. *) val join : 'a event event -> 'a event (** [bind e f] is [join (map f e)] *) val bind : 'a event -> ('a -> 'b event) -> 'b event val scan : ('a -> 'b -> 'a) -> 'a -> 'b event -> 'a event val filter : ('a -> bool) -> 'a event -> 'a event val filter_map : ('a -> 'b option) -> 'a event -> 'b event val zip : 'a event -> 'b event -> ('a * 'b) event val take_while : ('a -> bool) -> 'a event -> 'a event val take_while_in : ('a -> bool) -> 'a event -> 'a event val take_n : int -> 'a event -> 'a event val once : 'a event -> 'a event val drop_while : ('a -> bool) -> 'a event -> 'a event val drop_n : int -> 'a event -> 'a event val delay : int -> 'a event -> 'a event val pairwise : 'a event -> ('a * 'a) event (** [subscribe f e] attaches the [f] to the specified event. The [f] will be called when the [e] will occurred. *) val subscribe : ('a -> unit) -> 'a event -> unit (** [value e] returns a reference cell which store a latest value *) val value : 'a -> 'a event -> 'a ref (** [run ()] runs PEC event system and returns a number of queuing size of sended data. *) val run : unit -> int e.g. Using PEC, you can write a drag event from mouse events like this. let (+>) f g = g f (* E is PEC module *) let dragging mouse_down mouse_up mouse_move = E.bind mouse_down (fun dloc -> E.choose [ E.map (fun uloc -> `Drop (dloc, uloc)) mouse_up; E.map (fun mloc -> `Drag (dloc, mloc)) mouse_move; ] +> E.take_while_in (function `Drop _ -> false | _ -> true)) Regards, ogasawara -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs