- F# Basic Tutorial
- F# - Home
- F# - Overview
- F# - Environment Setup
- F# - Program Structure
- F# - Basic Syntax
- F# - Data Types
- F# - Variables
- F# - Operators
- F# - Decision Making
- F# - Loops
- F# - Functions
- F# - Strings
- F# - Options
- F# - Tuples
- F# - Records
- F# - Lists
- F# - Sequences
- F# - Sets
- F# - Maps
- F# - Discriminated Unions
- F# - Mutable Data
- F# - Arrays
- F# - Mutable Lists
- F# - Mutable Dictionary
- F# - Basic I/O
- F# - Generics
- F# - Delegates
- F# - Enumerations
- F# - Pattern Matching
- F# - Exception Handling
- F# - Classes
- F# - Structures
- F# - Operator Overloading
- F# - Inheritance
- F# - Interfaces
- F# - Events
- F# - Modules
- F# - Namespaces
- F# Useful Resources
- F# - Quick Guide
- F# - Useful Resources
- F# - Discussion
F# - Namespaces
A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace will not conflict with the same class names declared in another.
As per the MSDN library, a namespace lets you organize code into areas of related functionality by enabling you to attach a name to a grouping of program elements.
Declaring a Namespace
To organize your code in a namespace, you must declare the namespace as the first declaration in the file. The contents of the entire file then become part of the namespace.
namespace [parent-namespaces.]identifier
The following example illustrates the concept −
Example
namespace testing module testmodule1 = let testFunction x y = printfn "Values from Module1: %A %A" x y module testmodule2 = let testFunction x y = printfn "Values from Module2: %A %A" x y module usermodule = do testmodule1.testFunction ( "one", "two", "three" ) 150 testmodule2.testFunction (seq { for i in 1 .. 10 do yield i * i }) 200
When you compile and execute the program, it yields the following output −
Values from Module1: ("one", "two", "three") 150 Values from Module2: seq [1; 4; 9; 16; ...] 200
Advertisements
To Continue Learning Please Login
Login with Google