# Another question about using ppx with dune/jbuilder

**URL:** <https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941>\
**Category:** Ecosystem\
**Tags:** ppx\_deriving, jbuilder, dune\
**Created:** [May 3, 2018, 4:07am UTC](https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941 "2018-05-03T04:07:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [May 3, 2018, 4:07am UTC](https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941/1 "2018-05-03T04:07:39Z")

</div>

I can use `ppx_deriving make` successfully in `utop`. I’m trying to figure out how to use it with dune (as a first step to using `deriving` in other ways, along with other `ppx` processors). What should I have in the `jbuilder` file for this purpose? (I have read anything I can find that seems relevant in the jbuilder/dune docs or in the `ppx_deriving` README, but I have not yet figured this out. A tutorial on this sort of thing would be very welcome.)

foo.ml:

```auto
type t = {a : int; b : float} [@@deriving make]

let () =
  (* let make_t x y = {a=x; b=y} in *)
  let f y x = make_t x y in
  let foo1 = f 2.1 3 in
  Printf.printf "%f %d\n" foo1.b foo1.a

```

The best hypothesis I have about what should go in jbuild is something like this:

```auto
(jbuild_version 1)

(executables
 ((names (foo))
  (public_names (foo))
  (package bar)
  (preprocess (pps (ppx_deriving.std)))
  (libraries (core ppx_deriving.runtime))
  (modes (native))))

```

However, compiling with `jbuilder build @install` produces:

```auto
...
File "foo.ml", line 6, characters 14-20:
Error: Unbound value make_t
Hint: Did you mean make?

```

If I uncomment the definition of `make_t` in foo.ml, the executable builds and runs with expected output.

---

<div class="post-metadata">

**Author:** ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)\
**Post date:** [May 3, 2018, 6:11am UTC](https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941/2 "2018-05-03T06:11:47Z")

</div>

Isn’t this purely due to `ppx_deriving` calling the `deriver_type` functions just `deriver` it the type is called `t` as a convenience? Like `show_foobar` on `type foobar [@@deriving show]` but `show` on `type t [@@deriving show]`?

The message seems to point you to the fact that there is a `make` function.

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [May 3, 2018, 5:56pm UTC](https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941/3 "2018-05-03T17:56:27Z")

</div>

> [@Leonidas](#):
>
> The message seems to point you to the fact that there is a `make` function.

You’re right! Thanks. It didn’t occur to me that the behavior would be different for type `t` vs. other names. (Not very obvious!) I thought that the error message was referencing some other `make` function that was unrelated.

---

<div class="post-metadata">

**Author:** ![smolkaj](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/smolkaj/32/266_2.png) [@smolkaj](https://discuss.ocaml.org/u/smolkaj)\
**Post date:** [May 3, 2018, 6:19pm UTC](https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941/4 "2018-05-03T18:19:43Z")

</div>

This is due to the OCaml convention to call the “main” type of a module `t`. For example,

```auto
module List = struct
  type 'a t = Nil | Cons of 'a * 'a t
    [@@deriving eq, compare, hash, sexp]

  let empty = Nil

  let rec member xs x =
  ...
end

```

The convention makes for very readable code:

```auto
let l1 : List.t = List.empty in
let l2 : List.t = List.(cons 2 empty) in
if List.equal l1 l2 then
  List.hash l1
else
  List.hash l2

```

Compare that to

```auto
if List.equal_t l1 l2 then
  List.hash_t l1
else
  List.hash_t l2

```

It should be fairly uncontroversial that the `_t` suffix is both ugly and pointless.

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [May 3, 2018, 10:40pm UTC](https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941/5 "2018-05-03T22:40:08Z")

</div>

Yes, thanks @smolkaj. Nothing I’d seen hinted that `deriving make` worked this way.

EDIT: Ah, I found it. Earlier in the `ppx_deriving` README:

`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.`

---

<div class="post-metadata">

**Author:** ![lindig](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lindig/32/532_2.png) [@lindig](https://discuss.ocaml.org/u/lindig)\
**Post date:** [September 1, 2018, 1:02pm UTC](https://discuss.ocaml.org/t/another-question-about-using-ppx-with-dune-jbuilder/1941/6 "2018-09-01T13:02:28Z")

</div>

I believe the `ppx_deriving.runtime` does not have to declared as a library. In fact, I found the `jbuild` file below to be working. The library still is linked into the binary when required.

```auto
(jbuild_version 1)

(executables
 ((names (foo))
  (public_names (foo))
  (package bar)
  (preprocess (pps (ppx_deriving.std)))
  (modes (native))))

```
