使用模块向现有模块和类型添加新功能

模块可用于向现有模块和类型添加新功能。

namespace FSharp.Collections

module List =
    let pair item1 item2 = [ item1; item2 ]

然后可以调用新函数,就好像它是 List 的原始成员一样。

open FSharp.Collections    

module Testing =
    let result = List.pair "a" "b"
    // result is a list containing "a" and "b"