Indentation of comment after variant type declaration

I am using ocp-indent with tuareg and emacs, and I am spotting a discrepancy in the way a comment after a type definition is indented.

Record type definitions do not incur indentation after them, as I wish :
type a =
{f:int}
(* comment *)

However, there is an indent after the definition of a variant type (or sum type) :
type b =
| A
(* comment *)

I believe it is treating the comment as a part of the constructor rather than being after the definition, as I mean it.

How do I change this behaviour ?

I’m not sure you can somehow it’s inherently ambiguous.

For example if you write doc strings you need to add a fake empty comment so that the docstring for the type doesn’t get attached to the last case.

type b = 
| A (** *)
(** Doc string for [b].*) 

That being said there’s another solution to your problem but it leads to a different layout which is to use strict_with=always .

This never indents match bars (see my example above). I provides more room to express yourself on 80 columns and I find it better from a graphic design perspective (visually more blocky and cohesive). So that’s (one of the) parameters I work with.

Incidentally that fixes your problem :–)

Ah, but then it produces
type a =
| A
which I do not want.

Not going to convince a preference :–) but overall it’s more consistent.

The programming guidelines have a mixture of indentations (or lack of) depending on function or match or type which overall results in an undesirable visually busy design that lacks consistency.

In general I find the bars provide a nice signifier for the block, there’s no need for indentation to delineate it. In turn it helps you to better fight the 80 columns limit :–)