caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Is it possible to get back some OCaml code after ppx processing ?
@ 2016-03-23 16:39 Francois Berenger
  2016-03-23 17:02 ` Louis Roché
  2016-03-23 17:05 ` Nicolas Ojeda Bar
  0 siblings, 2 replies; 5+ messages in thread
From: Francois Berenger @ 2016-03-23 16:39 UTC (permalink / raw)
  To: caml-list

Dear list,

I am completely new to the -ppx option of the compiler, so please
forgive in advance my (probably stupid) two questions.

Here is some example code:
---
type t = {
   i: int;
   f: float
} [@@deriving sexp]
---

1) I'd like to see all the functions automatically created
by the magical spell "[@@deriving sexp]".
At least their names and type signatures would be nice.
How to do that?

2) If that's not possible, I'd like to get back some
OCaml code corresponding to the AST after ppx processing.
If that's possible, how to do that?

Thanks a lot,
Francois.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Is it possible to get back some OCaml code after ppx processing ?
  2016-03-23 16:39 [Caml-list] Is it possible to get back some OCaml code after ppx processing ? Francois Berenger
@ 2016-03-23 17:02 ` Louis Roché
  2016-03-24  9:27   ` Goswin von Brederlow
  2016-03-23 17:05 ` Nicolas Ojeda Bar
  1 sibling, 1 reply; 5+ messages in thread
From: Louis Roché @ 2016-03-23 17:02 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

Hi,

1) With utop, you will get what you want:

utop # type t = {
  i: int;
  f: float
} [@@deriving eq,show];;
type t = { i : int; f : float; }
val equal : t -> t -> bool = <fun>
val pp : Format.formatter -> t -> unit = <fun>
val show : t -> bytes = <fun>

2) I believe that you are looking for an option like -dsource for ocamlc

Louis


2016-03-23 17:39 GMT+01:00 Francois Berenger <francois.berenger@inria.fr>:

> Dear list,
>
> I am completely new to the -ppx option of the compiler, so please
> forgive in advance my (probably stupid) two questions.
>
> Here is some example code:
> ---
> type t = {
>   i: int;
>   f: float
> } [@@deriving sexp]
> ---
>
> 1) I'd like to see all the functions automatically created
> by the magical spell "[@@deriving sexp]".
> At least their names and type signatures would be nice.
> How to do that?
>
> 2) If that's not possible, I'd like to get back some
> OCaml code corresponding to the AST after ppx processing.
> If that's possible, how to do that?
>
> Thanks a lot,
> Francois.
>
> --
> 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
>

[-- Attachment #2: Type: text/html, Size: 2154 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Is it possible to get back some OCaml code after ppx processing ?
  2016-03-23 16:39 [Caml-list] Is it possible to get back some OCaml code after ppx processing ? Francois Berenger
  2016-03-23 17:02 ` Louis Roché
@ 2016-03-23 17:05 ` Nicolas Ojeda Bar
  1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Ojeda Bar @ 2016-03-23 17:05 UTC (permalink / raw)
  To: Francois Berenger; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1099 bytes --]

Hi Francois,

You can use ppx_tools (https://github.com/alainfrisch/ppx_tools) to do it:

  ocamlfind ppx_tools/rewriter ./my_ppx_rewriter foo.ml

Cheers,
Nicolas


On Wed, Mar 23, 2016 at 5:39 PM, Francois Berenger <
francois.berenger@inria.fr> wrote:

> Dear list,
>
> I am completely new to the -ppx option of the compiler, so please
> forgive in advance my (probably stupid) two questions.
>
> Here is some example code:
> ---
> type t = {
>   i: int;
>   f: float
> } [@@deriving sexp]
> ---
>
> 1) I'd like to see all the functions automatically created
> by the magical spell "[@@deriving sexp]".
> At least their names and type signatures would be nice.
> How to do that?
>
> 2) If that's not possible, I'd like to get back some
> OCaml code corresponding to the AST after ppx processing.
> If that's possible, how to do that?
>
> Thanks a lot,
> Francois.
>
> --
> 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
>

[-- Attachment #2: Type: text/html, Size: 2007 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Is it possible to get back some OCaml code after ppx processing ?
  2016-03-23 17:02 ` Louis Roché
@ 2016-03-24  9:27   ` Goswin von Brederlow
  2016-03-24 10:37     ` Jeremie Dimino
  0 siblings, 1 reply; 5+ messages in thread
From: Goswin von Brederlow @ 2016-03-24  9:27 UTC (permalink / raw)
  To: caml-list

On Wed, Mar 23, 2016 at 06:02:49PM +0100, Louis Roché wrote:
> Hi,
> 
> 1) With utop, you will get what you want:
> 
> utop # type t = {
>   i: int;
>   f: float
> } [@@deriving eq,show];;
> type t = { i : int; f : float; }
> val equal : t -> t -> bool = <fun>
> val pp : Format.formatter -> t -> unit = <fun>
> val show : t -> bytes = <fun>
> 
> 2) I believe that you are looking for an option like -dsource for ocamlc
> 
> Louis
> 
> 
> 2016-03-23 17:39 GMT+01:00 Francois Berenger <francois.berenger@inria.fr>:
> 
> > Dear list,
> >
> > I am completely new to the -ppx option of the compiler, so please
> > forgive in advance my (probably stupid) two questions.
> >
> > Here is some example code:
> > ---
> > type t = {
> >   i: int;
> >   f: float
> > } [@@deriving sexp]
> > ---
> >
> > 1) I'd like to see all the functions automatically created
> > by the magical spell "[@@deriving sexp]".
> > At least their names and type signatures would be nice.
> > How to do that?
> >
> > 2) If that's not possible, I'd like to get back some
> > OCaml code corresponding to the AST after ppx processing.
> > If that's possible, how to do that?
> >
> > Thanks a lot,
> > Francois.

'ocamlc -i' should work too.

MfG
	Goswin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Is it possible to get back some OCaml code after ppx processing ?
  2016-03-24  9:27   ` Goswin von Brederlow
@ 2016-03-24 10:37     ` Jeremie Dimino
  0 siblings, 0 replies; 5+ messages in thread
From: Jeremie Dimino @ 2016-03-24 10:37 UTC (permalink / raw)
  To: Goswin von Brederlow; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1859 bytes --]

For the case of Jane Street ppx rewriters (assuming you are using
ppx_sexp_conv), you can install ppx_jane and do:

  ppx-jane file.ml

On Thu, Mar 24, 2016 at 9:27 AM, Goswin von Brederlow <goswin-v-b@web.de>
wrote:

> On Wed, Mar 23, 2016 at 06:02:49PM +0100, Louis Roché wrote:
> > Hi,
> >
> > 1) With utop, you will get what you want:
> >
> > utop # type t = {
> >   i: int;
> >   f: float
> > } [@@deriving eq,show];;
> > type t = { i : int; f : float; }
> > val equal : t -> t -> bool = <fun>
> > val pp : Format.formatter -> t -> unit = <fun>
> > val show : t -> bytes = <fun>
> >
> > 2) I believe that you are looking for an option like -dsource for ocamlc
> >
> > Louis
> >
> >
> > 2016-03-23 17:39 GMT+01:00 Francois Berenger <francois.berenger@inria.fr
> >:
> >
> > > Dear list,
> > >
> > > I am completely new to the -ppx option of the compiler, so please
> > > forgive in advance my (probably stupid) two questions.
> > >
> > > Here is some example code:
> > > ---
> > > type t = {
> > >   i: int;
> > >   f: float
> > > } [@@deriving sexp]
> > > ---
> > >
> > > 1) I'd like to see all the functions automatically created
> > > by the magical spell "[@@deriving sexp]".
> > > At least their names and type signatures would be nice.
> > > How to do that?
> > >
> > > 2) If that's not possible, I'd like to get back some
> > > OCaml code corresponding to the AST after ppx processing.
> > > If that's possible, how to do that?
> > >
> > > Thanks a lot,
> > > Francois.
>
> 'ocamlc -i' should work too.
>
> MfG
>         Goswin
>
> --
> 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
>



-- 
Jeremie

[-- Attachment #2: Type: text/html, Size: 3345 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-03-24 10:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-23 16:39 [Caml-list] Is it possible to get back some OCaml code after ppx processing ? Francois Berenger
2016-03-23 17:02 ` Louis Roché
2016-03-24  9:27   ` Goswin von Brederlow
2016-03-24 10:37     ` Jeremie Dimino
2016-03-23 17:05 ` Nicolas Ojeda Bar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).