Namespace
Syntax
namespace [rec] [parent.]identifier
rec
for recursive ā see slide nextparent
for grouping namespaces
Content
A namespace
F⯠can only contain local types and modules
Cannot contain values or functions ā
By comparison, it's the same in C⯠with
namespace
that contains classes / enums only
What about nested namespaces?
Only happens declaratively
namespace [parent.]identifier
2 namespaces declared in the same file =
not nestedbut independent
Scope
Several files can share the same namespace
Several namespaces can be declared in a single file
They will not be
nestedMay cause confusion ā
ā Recommendations \
Only one namespace per file, declared at the top
Organize files by grouping them in directories with the same name as the namespace
0 (root)
/
Root
1
/Lev1
Root.Lev1
2
/Lev1/Lev2
Root.Lev1.Lev2
š Recursive namespace
Extends the default unidirectional visibility: from bottom to top ā each element can see all the elements in a recursive namespace
ā ļø Drawbacks: slow compilation, risk of circular reference
ā Recommendation: handy but only for very few use cases
Last updated
Was this helpful?