Fsharp-namespaces
提供:Dev Guides
F#-名前空間
- 名前空間*は、ある名前のセットを別の名前のセットから分離する方法を提供するために設計されています。 あるネームスペースで宣言されたクラス名は、別のネームスペースで宣言された同じクラス名と競合しません。
MSDNライブラリごとに、*名前空間*を使用すると、プログラム要素のグループに名前を付けることができるため、コードを関連機能の領域に整理できます。
名前空間の宣言
名前空間でコードを整理するには、ファイルの最初の宣言として名前空間を宣言する必要があります。 ファイル全体の内容は、名前空間の一部になります。
namespace [parent-namespaces.]identifier
次の例は、概念を示しています-
例
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
あなたがプログラムをコンパイルして実行すると、次の出力が得られます-
Values from Module1: ("one", "two", "three") 150
Values from Module2: seq [1; 4; 9; 16; ...] 200