W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
// Top-level module declaration. module [accessibility-modifier] [qualified-namespace.]module-name declarations // Local module declaration. module [accessibility-modifier] module-name = declarations
請注意,可訪問修飾符可以是下列之一:公共,私有或內(nèi)部的。默認為公開 。
下面的實例將展示其中的概念
該模塊文件Arithmetic.fs
module Arithmetic let add x y = x + y let sub x y = x - y let mult x y = x * y let div x y = x / y
程序文件main.fs
// Fully qualify the function name. open Arithmetic let addRes = Arithmetic.add 25 9 let subRes = Arithmetic.sub 25 9 let multRes = Arithmetic.mult 25 9 let divRes = Arithmetic.div 25 9 printfn "%d" addRes printfn "%d" subRes printfn "%d" multRes printfn "%d" divRes
當(dāng)你編譯和執(zhí)行程序,它產(chǎn)生以下輸出
34 16 225 2 110 90 1000 10
// Module1 module module1 = // Indent all program elements within modules that are declared with an equal sign. let value1 = 100 let module1Function x = x + value1 // Module2 module module2 = let value2 = 200 // Use a qualified name to access the function. // from module1. let module2Function x = x + (module1.module1Function value2) let result = module1.module1Function 25 printfn "%d" result let result2 = module2.module2Function 25 printfn "%d" result2
當(dāng)你編譯和執(zhí)行程序,它產(chǎn)生以下輸出
125 325
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: