From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8FEk1W0022059 for ; Thu, 15 Sep 2011 16:46:01 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlIEABkPck7RVdQpkGdsb2JhbABDmGI1hxEBhxwIFAEBAQEJCQ0HFAQigVMBAQEBAgESAhMZARsSCwEDAQsGBQsZASEiAREBBQEKEgYTEhCHVQSZTwqLQIJahRA7iG0CAwaGbgSCVJBzjH89g3A X-IronPort-AV: E=Sophos;i="4.68,387,1312149600"; d="scan'208";a="109220634" Received: from mail-vw0-f41.google.com ([209.85.212.41]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 15 Sep 2011 16:45:55 +0200 Received: by vwm42 with SMTP id 42so4925390vwm.0 for ; Thu, 15 Sep 2011 07:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=x8omOhFzc/8w+m1kS9wGz4UqfSzDzlt/wraKRJXcBn4=; b=ISx/8fpvKgXhR8cxm15G4Suf7h7AvtibKe4mCM7Lvo/R6qVx/u7u3sVm18l9J95KAD rpxcoRGECv5rt3Ot92CAodbfIgsSr00XI5eMEHKrxKIqo6Oy8/fy7sAcyIop7gtaf+f4 sOrymjGySSma7U7+wSZZAOJJcYIdlsLAmEXDI= Received: by 10.52.115.194 with SMTP id jq2mr1074952vdb.434.1316097954211; Thu, 15 Sep 2011 07:45:54 -0700 (PDT) MIME-Version: 1.0 Received: by 10.221.13.202 with HTTP; Thu, 15 Sep 2011 07:45:34 -0700 (PDT) In-Reply-To: <4E72096C.1040904@itpl.co.jp> References: <4E72096C.1040904@itpl.co.jp> From: Philippe Veber Date: Thu, 15 Sep 2011 16:45:34 +0200 Message-ID: To: Satoshi Ogasawara Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=bcaec548a05d0ce7b304acfbeff0 X-Validation-by: philippe.veber@gmail.com Subject: Re: [Caml-list] a push style event combinator --bcaec548a05d0ce7b304acfbeff0 Content-Type: text/plain; charset=ISO-8859-1 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 > > --bcaec548a05d0ce7b304acfbeff0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 (continu= ous function of time) in PEC (or maybe signals can be emulated somehow ?). = Also could you comment on the 'no memory leaks' feature ?

cheers,
=A0 Philippe.


2011/9/1= 5 Satoshi Ogasawara <ogasawara@itpl.co.jp>
Hello,

I'd like to announce the release of PEC, a push style event combinator.=

=A0PEC : 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 fo= llows.

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.<= br> =A0 =A0"Inner event" is a event comes from outer event [ee]. *)<= br> val join : 'a event event -> 'a event
(** [bind e f] is [join (map f e)] *)
val bind : 'a event -> ('a -> 'b event) -> 'b even= t
val scan : ('a -> 'b -> 'a) -> 'a -> 'b eve= nt -> '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<= br> val take_while_in : ('a -> bool) -> 'a event -> 'a eve= nt
val take_n : int -> 'a event -> 'a event
val once : 'a event -> 'a event
val drop_while : ('a -> bool) -> 'a event -> 'a event<= br> 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.
=A0 =A0The [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.
=A0Using PEC, you can write a drag event from mouse events like this.

let (+>) f g =3D g f
(* E is PEC module *)
let dragging mouse_down mouse_up mouse_move =3D
=A0E.bind mouse_down (fun dloc -> E.choose [
=A0 =A0E.map (fun uloc -> `Drop (dloc, uloc)) mouse_up;
=A0 =A0E.map (fun mloc -> `Drag (dloc, mloc)) mouse_move;
=A0]
=A0+> E.take_while_in (function `Drop _ -> false | _ -> true))


Regards,
=A0ogasawara

--
Caml-list mailing list. =A0Subscription 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


--bcaec548a05d0ce7b304acfbeff0--