Le 19 janv. 2017 à 12:39, Gabriel Scherer <gabriel.scherer@gmail.com> a écrit :

the min, max issues can be avoided without much trouble by using
specialized comparison, as provided in standard library extensions.

Note that min/max are already optimized from generic to specialized
when the type information is known at type-checking time. (It used to
be the case that only fully applied calls were optimized, this was
improved by Frédéric Bour to extend to non-applied primitives in 4.03
(eg. "let eq : int -> int -> _ = (=)"). That does not work when those
functions are used inside a functor body at an abstract type (which is
when we want inlining and specialization to interact better), but
there neither do Float.equal or Int.compare.

Alas, min/max cannot benefit from this optimisation.

In Pervasives, they are defined as:

let min x y = if x <= y then x else y
let max x y = if x >= y then x else y

Specialization only happens for primitives, here it is a plain definition.
So no specialization unless the definitions are copied and annotated :(.