# Ppx\_variants\_conv on mutually dependent types

**URL:** <https://discuss.ocaml.org/t/ppx-variants-conv-on-mutually-dependent-types/17176>\
**Category:** Ecosystem\
**Tags:** ppx\
**Created:** [August 28, 2025, 2:21pm UTC](https://discuss.ocaml.org/t/ppx-variants-conv-on-mutually-dependent-types/17176 "2025-08-28T14:21:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ban](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ban/32/5017_2.png) [@Ban](https://discuss.ocaml.org/u/Ban)\
**Post date:** [August 28, 2025, 2:21pm UTC](https://discuss.ocaml.org/t/ppx-variants-conv-on-mutually-dependent-types/17176/1 "2025-08-28T14:21:07Z")

</div>

I am trying to use Jane Street’s `ppx_variants_conv` ([GitHub - janestreet/ppx\_variants\_conv: Generation of accessor and iteration functions for ocaml variant types](https://github.com/janestreet/ppx_variants_conv)) for a problem that includes mutually dependent types. Unfortunately, the ppx fails with a `not supported` error. Do we know whether there is a fundamental issue that prevents this type of rewriter to work on this scenario, and (if not) whether we can expect a support in the near future?

Or are there alternative options available out there?

For reference, this is the type of code I would like to write. Ignore the exact names, I did not want to use `foo` and `bar`.

```auto
type t =
  | Point of t'
  | Line of (int * int)
  [@@deriving variants]
and t' = Pair of (t * t)

```

Cheers, Alban.

---

<div class="post-metadata">

**Author:** ![smuenzel](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/smuenzel/32/3945_2.png) [@smuenzel](https://discuss.ocaml.org/u/smuenzel)\
**Post date:** [August 28, 2025, 8:36pm UTC](https://discuss.ocaml.org/t/ppx-variants-conv-on-mutually-dependent-types/17176/2 "2025-08-28T20:36:31Z")

</div>

I think it’s probably not too hard to add support recursive definitions in `ppx_variants_conv`, but for now, you can probably work around by unwrapping the recursion:

```ocaml
type 't t'' = | Point of 't | Line of int * int [@@deriving variants]
type t = t' t'' and t' = Pair of t * t

```

---

<div class="post-metadata">

**Author:** ![Ban](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ban/32/5017_2.png) [@Ban](https://discuss.ocaml.org/u/Ban)\
**Post date:** [August 29, 2025, 9:27am UTC](https://discuss.ocaml.org/t/ppx-variants-conv-on-mutually-dependent-types/17176/3 "2025-08-29T09:27:47Z")

</div>

This is such a neat trick. Thanks for that, Stefan.

---

<div class="post-metadata">

**Author:** ![sim642](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sim642/32/3597_2.png) [@sim642](https://discuss.ocaml.org/u/sim642)\
**Post date:** [August 29, 2025, 9:59am UTC](https://discuss.ocaml.org/t/ppx-variants-conv-on-mutually-dependent-types/17176/4 "2025-08-29T09:59:48Z")

</div>

By the way, `Pair of (t * t)` and `Pair of t * t` are subtly different! This is, for example, explained here: [ocaml - Is a multiple argument constructor ever useful over a single tuple argument constructor? - Stack Overflow](https://stackoverflow.com/q/67079629).  
The latter is generally preferred.
