Why Does F# Contain Both Modules and Namespaces

%flanguage-design

I've been assuming that F# includes the module keyword in addition to the namespace keyword due to backwards compatibility with OCaml. Is this the only reason for the inclusion of the module keyword or are there other reasons module was included?

Best Answer

Namespaces are well defined in the .Net universe, and they don't include the things that make up a module, except inside something very much like a module.

Given that they were designing a language to run on the CLR, making it incompatible with other languages would not have made sense.

On a slightly different tangent, namespaces and modules do NOT overlap -- in particular, you can't define another namespace inside a module, and defining another namespace is the sole purpose of namespaces. They may bear a superficial simularity, but they are distinct concepts.

Related Topic