Possible Duplicate:
Two fields of two records have same label in OCaml
In Ocaml 3.12.0, is it necessary that any labels of a record have globally unique names?
type foo = { a : int; b : char; }
# type bar = {a : int; b : string};;
type bar = { a : int; b : string; }
# {a=3; b='a'};;
{a=3; b='a'};;
Error: This expression has type char but an expression was expected of type
string
I guess if the record is created anonymously, the only way for the compiler to know which type I’m referring to is the record names. Does declaring bar hide foo?
No, record labels don’t have to be globally unique. But they have to be unique in module level.
Declaring
bardoesn’t hidefoo; therefore, type inference is broken when refering tobfield.You can easily create submodules and use module names to distinguish between records with the same label: