F# Basic Tutorial
F# Useful Resources
Selected Reading
- F# - Namespaces
- F# - Modules
- F# - Events
- F# - Interfaces
- F# - Inheritance
- F# - Operator Overloading
- F# - Structures
- F# - Classes
- F# - Exception Handling
- F# - Pattern Matching
- F# - Enumerations
- F# - Delegates
- F# - Generics
- F# - Basic I/O
- F# - Mutable Dictionary
- F# - Mutable Lists
- F# - Arrays
- F# - Mutable Data
- F# - Discriminated Unions
- F# - Maps
- F# - Sets
- F# - Sequences
- F# - Lists
- F# - Records
- F# - Tuples
- F# - Options
- F# - Strings
- F# - Functions
- F# - Loops
- F# - Decision Making
- F# - Operators
- F# - Variables
- F# - Data Types
- F# - Basic Syntax
- F# - Program Structure
- F# - Environment Setup
- F# - Overview
- F# - Home
F# Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
F# - Namespaces
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 confpct with the same class names declared in another.
As per the MSDN pbrary, a namespace lets you organize code into areas of related functionapty by enabpng 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; ...] 200Advertisements