The cost factory interface.
A valid cost factory should also satisfy the following contracts.
le
is a total ordering.If le a b
and le c d
then le (combine a c) (combine b d)
If a
<= b
, then le (text a l) (text b l)
If a
<= b
, then le (newline a) (newline b)
text c (a + b) = combine (text c a) (text (c + a) b)
combine
is associative and has the identity equal to text 0 0
text c 0
= text 0 0
for any c
If a
<= b
, then le (two_columns_overflow a) (two_columns_overflow b)
If a
<= b
, then le (two_columns_bias a) (two_columns_bias b)
See default_cost_factory
, the cost factory section , and the paper for examples of cost factories.
val text : int -> int -> t
text c l
calculates a cost for a text placement at column position c
with length l
newline i
calculates a cost for a newline and indentation at level i
val combine : t -> t -> t
combine x y
combines the costs x
and y
together
le x y
tests if the cost x
is less than or equal to the cost y
.
val two_columns_bias : int -> t
two_columns_bias i
is the bias cost, added to each possible column separator so that the leftmost column separator is preferred.
val two_columns_overflow : int -> t
two_columns_overflow i
is the cost due to exceeding the column separator. Make this cost greater than the usual overflow cost (for exceeding the page width limit) to prefer going over the page width limit instead of going over the column separator.
limit
is the computation width limit .
val string_of_cost : t -> string
string_of_cost c
produces a string representation of a cost c
debug_format s is_tainted cost
produces a debugging string from the output of the core printer.