Phantom type
A type parameter that appears in a type's signature but in none of its fields, used purely to keep two otherwise identical representations from being mixed up. Unlike a GADT it adds no information at pattern-match time: it constrains what the caller may do, not what the compiler can learn.
A phantom type parameter appears in a type's declaration and in none of its constructors. It carries no data, costs nothing at runtime, and exists only so the typechecker can refuse to let two representationally identical values be confused.
A unit-tagged distance. Both are floats at runtime; neither can be passed where the other is expected.
type metrestype feettype 'unit length = Length of float (* 'unit occurs nowhere on the right *)let metres (x : float) : metres length = Length xlet feet (x : float) : feet length = Length xlet add (Length a) (Length b) : 'u length = Length (a +. b)let _ = add (metres 3.) (metres 4.) (* fine *)let _ = add (metres 3.) (feet 4.) (* type error *)
The difference from a GADT is what happens on the way out. A phantom parameter constrains callers but tells a pattern match nothing: matching Length x learns no more about 'unit than was already known. A GADT parameter is recovered by matching, which is why it can change the result type of a branch and a phantom cannot.
see also
read more