Can I use PPX_deriving with modules?

I am trying to get my head around PPX_deriving.

I (seem) to understand that when I adorn a type foo with a deriving attribute (e.g. show and eq)
I will get
foo_show: foo -> string
and
foo_eq: foo -> foo -> bool

But what I really would like to have is something like this

module type Foo = sig
  type t
end [@@deriving show, eq]

which then expands into

module type Foo = sig
  type t
  val show: t -> string
  val eq: t -> t -> bool
end

Is this possible?

What’s wrong with

module type Foo = sig
  type t [@@deriving show, eq]
end

?

2 Likes

Wouldn’t that create the following signature?

module type Foo = sig
  type t
  val show_t: t -> string
  val eq_t: t -> t -> bool
end

that is it would append or prepend the name of the type to each of the generated functions

Not for the type t :

By default, the functions generated by a plugin for a type foo are called fn_foo or foo_fn . However, if the type is called type t , the function will be named foo . The defaults can be overridden by an affix = true|false plugin option.

source

Sorry to ask again. But I find the docs for PPX deriving pretty confusing.

Lets say I have a type t that derives for example show and eq.
What are defined functions (their name and signature)?

I am asking because this doc snippet you pasted I read that I would end up with a function val t: ? -> ? which makes no sense to me

for type t the functions are simply called pp for show instead of pp_t etc.

i have a related question: is there a way to set defaults for ppx_deriving module-wide. for instance, for show, i would like to set the option of not printing module paths (i think it’s {paths = False} or something like that) once and for all, and not in every single [@@deriving ..] annotation

The name t for types is special-cased, so to speak. So no.

At least that is how I remember it