名称空间旨在提供一种使一组名称彼此分开的方法,在一个名称空间中声明的类名不会与在另一个名称空间中声明的相同类名冲突。
要在命名空间中组织代码,必须将命名空间声明为文件中的第一个声明,然后,整个文件的内容将成为命名空间的一部分。
链接:https://www.learnfk.comhttps://www.learnfk.com/fsharp/fsharp-namespaces.html
来源:LearnFk无涯教程网
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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)