From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 2B0967FA56 for ; Wed, 23 Jul 2014 16:37:30 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yotambarnoy@gmail.com) identity=pra; client-ip=209.85.216.53; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of yotambarnoy@gmail.com designates 209.85.216.53 as permitted sender) identity=mailfrom; client-ip=209.85.216.53; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="yotambarnoy@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-qa0-f53.google.com) identity=helo; client-ip=209.85.216.53; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="yotambarnoy@gmail.com"; x-sender="postmaster@mail-qa0-f53.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AisBAF7Iz1PRVdg1lGdsb2JhbABZg2BXBIJ0rzmTV4Fhh0UBgQMIFg8BAQEBBwsLCRIrhAQBAQMBEhEEGQEbEgsBAwELBgULAxcdAgIiAREBBQEKEgYTEgIOiAsBAwkIDZxYaosogXKDEIpEChknAwpkhjgRAQUOjzkEB4J4gU4FhG8FiVGMaIFSihqGYxgpgnaCHiEv X-IPAS-Result: AisBAF7Iz1PRVdg1lGdsb2JhbABZg2BXBIJ0rzmTV4Fhh0UBgQMIFg8BAQEBBwsLCRIrhAQBAQMBEhEEGQEbEgsBAwELBgULAxcdAgIiAREBBQEKEgYTEgIOiAsBAwkIDZxYaosogXKDEIpEChknAwpkhjgRAQUOjzkEB4J4gU4FhG8FiVGMaIFSihqGYxgpgnaCHiEv X-IronPort-AV: E=Sophos;i="5.01,717,1400018400"; d="scan'208";a="72557373" Received: from mail-qa0-f53.google.com ([209.85.216.53]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 23 Jul 2014 16:37:11 +0200 Received: by mail-qa0-f53.google.com with SMTP id v10so1334841qac.26 for ; Wed, 23 Jul 2014 07:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=kHmwc6ByPckMFeePVoy1n9M3cqgAfqmeBdwSDjKWzo0=; b=IXj9VxooFdCeujKxzyweIEYt7seb0Q5de0CTXSMMZ3TD6BPEtIdR8MG+oLp5EsMhJz K/jICCcCysxx1mFKmSiTsMZhL5GtJxTiRTSbcDjDWtm4BkrWzCFnZI0WkpWVt+eFJVXR hyxW68gM+JQwYA0lmo8zvqk/5Gb3qXhycpk3TPUy1prs8KbsV0mG84/pi/75Ux1zjILR 6K9f9zK9nzuWcyYt1QUsBLvusRAXNXN6cOQwwQAOaXXCg9mUBelf1rHoFjO2hmlFOVc5 Np3QOA3tkgj+RHbXMLy11p9LCjgjcjzZ3J+00dSX5U80ahYixc4T7kgzB4QSaexKsu0J 14aw== X-Received: by 10.140.94.70 with SMTP id f64mr2783009qge.64.1406126230463; Wed, 23 Jul 2014 07:37:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.33.14 with HTTP; Wed, 23 Jul 2014 07:36:50 -0700 (PDT) In-Reply-To: <0618b5ce9c054e91507c03eae7e7de0c@whitequark.org> References: <0618b5ce9c054e91507c03eae7e7de0c@whitequark.org> From: Yotam Barnoy Date: Wed, 23 Jul 2014 10:36:50 -0400 Message-ID: To: Peter Zotov Cc: Ocaml Mailing List Content-Type: multipart/alternative; boundary=001a1138fd3a79ec5c04fedd463e Subject: Re: [Caml-list] [ANN] ppx_deriving 0.1 --001a1138fd3a79ec5c04fedd463e Content-Type: text/plain; charset=UTF-8 Very nice. I've never used any of the deriving extensions before, but I have an aesthetic suggestions. Would it perhaps make sense to generate a module per derived type? For example a type t would generate a module T_ (the underscore or any other suffix would reduce mixups with pre-existing modules). You could then use code such as 'if T_.(a = b && b = c) ...' or 'T_.show x ...' which allows you to keep the infix notation for = which is important IMO. You could even generate T_ as having internal Eq, Ord, and Show modules (as requested by the user), which would be included in the T_ module. This would allow you to easily pass them as first class modules to functions accepting Eq, Ord or Show signatures. Yotam On Wed, Jul 23, 2014 at 5:55 AM, Peter Zotov wrote: > Hello, > > I'm glad to announce an initial release of ppx_deriving, > a modular syntax extension for type-driven code generation. > It will be shortly available in OPAM. > > I will introduce ppx_deriving with an example: > > # #require "ppx_deriving";; > # type file = { > kind : [ `File | `Dir ]; > name : string; > perm : int [@printer fun fmt -> Format.fprintf fmt "0o%03o"]; > } [@@deriving Show, Eq];; > type file = { kind : [ `Dir | `File ]; name : bytes; perm : int; } > val pp_file : Format.formatter -> file -> unit = > val show_file : file -> bytes = > val equal_file : file -> file -> bool = > # print_endline (show_file { kind = `Dir; name = "bin"; perm = 0o755 });; > { kind = `Dir; name = "bin"; perm = 0o755 } > - : unit = () > > A more thorough description is available in README[1]. > > While I intend this release to primarily serve as a preview for > the community and a means to gather feedback, it is fully usable > and documented. Some of the planned features (marked "TBD" in README) > are not yet implemented. > > I hope that ppx_deriving can serve as a future replacement to both > ocsigen's deriving and JaneStreet's type_conv. If you are responsible > for these libraries, please get in touch. The OCaml ecosystem would > benefit from a single type-driven code generation mechanism. > > I welcome any comments. > > [1]: https://github.com/whitequark/ppx_deriving/ > > -- > Peter Zotov > sip:whitequark@sipnet.ru > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --001a1138fd3a79ec5c04fedd463e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Very nice.

I've never used any of t= he deriving extensions before, but I have an aesthetic suggestions. Would i= t perhaps make sense to generate a module per derived type? For example a t= ype t would generate a module T_ (the underscore or any other suffix would = reduce mixups with pre-existing modules). You could then use code such as

'if T_.(a =3D b && b =3D c) ...'
<= div>
or =C2=A0'T_.show x ...'

which allows you to keep the infix notation for =3D which is important IM= O.=C2=A0

You could even generate T_ as having internal Eq, Ord, = and Show modules (as requested by the user), which would be included in the= T_ module. This would allow you to easily pass them as first class modules= to functions accepting Eq, Ord or Show signatures.

Yotam



On Wed, Jul 23, 2014 at 5:55 AM, Pet= er Zotov <whitequark@whitequark.org> wrote:
Hello,

I'm glad to announce an initial release of ppx_deriving,
a modular syntax extension for type-driven code generation.
It will be shortly available in OPAM.

I will introduce ppx_deriving with an example:

# #require "ppx_deriving";;
# type file =3D {
=C2=A0 kind : [ `File | `Dir ];
=C2=A0 name : string;
=C2=A0 perm : int [@printer fun fmt -> Format.fprintf fmt "0o%03o&q= uot;];
} [@@deriving Show, Eq];;
type file =3D { kind : [ `Dir | `File ]; name : bytes; perm : int; }
val pp_file : Format.formatter -> file -> unit =3D <fun>
val show_file : file -> bytes =3D <fun>
val equal_file : file -> file -> bool =3D <fun>
# print_endline (show_file { kind =3D `Dir; name =3D "bin"; perm = =3D 0o755 });;
{ kind =3D `Dir; name =3D "bin"; perm =3D 0o755 }
- : unit =3D ()

A more thorough description is available in README[1].

While I intend this release to primarily serve as a preview for
the community and a means to gather feedback, it is fully usable
and documented. Some of the planned features (marked "TBD" in REA= DME)
are not yet implemented.

I hope that ppx_deriving can serve as a future replacement to both
ocsigen's deriving and JaneStreet's type_conv. If you are responsib= le
for these libraries, please get in touch. The OCaml ecosystem would
benefit from a single type-driven code generation mechanism.

I welcome any comments.

=C2=A0 [1]: https://github.com/whitequark/ppx_deriving/

--
Peter Zotov
sip:whitequ= ark@sipnet.ru

--
Caml-list mailing list. =C2=A0Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners<= /a>
Bug reports:
http://caml.inria.fr/bin/caml-bugs

--001a1138fd3a79ec5c04fedd463e--