Split F# modules across multiple files

前端 未结 5 1874
攒了一身酷
攒了一身酷 2021-01-01 08:51

Is it possible to split an F# module across files?

According to the book I have it is, but the book is probably outdated (Foundations of F#)

5条回答
  •  耶瑟儿~
    2021-01-01 09:38

    Like Kurt says, you can add extension methods to types, and thus

    // File1.fs
    namespace Foo
    
    type Mine() =
        static member f1 () = ()
    

    then

    // File2.fs
    type Foo.Mine with
        static member f2() = ()
    
    Foo.Mine.    // both f1 and f2 here
    

    Since it's a class and not a module, you lose the ability to do 'open Mine' (but gain the ability to overload); thus this may or may not be an acceptable alternative for you depending on exactly what you're doing.

提交回复
热议问题