Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any difference between top-level modules and local modules?

Tags:

module

f#

I am a newbe to F#, but am quite familiar with C#. And I was wondering if there is a difference between declaring top level modules and local modules (e.g. performance, etc.), other than that the namespace declaration is not needed for top-level modules (it is part of the module declaration). I cannot find anything in the documentation (MSDN F# Modules) specifying other differences.

Basically, coming from the C# world I prefer

//Version 1
namespace My.Namespace

module MyModule = 
    let a = 1

over

//Version 2
module My.Namespace.MyModule
let a = 1

Given that in both versions there will be only one module in the file, does Version 2 bring any disadvantages (compared to Version 1)?

like image 364
Stephan Kunz Avatar asked Nov 21 '13 16:11

Stephan Kunz


1 Answers

Those are equivalent. According to F# 3.0 specs:

An implementation file that begins with a module declaration defines a single namespace declaration group with one module. For example:

module MyCompany.MyLibrary.MyModule
    let x = 1

is equivalent to:

namespace MyCompany.MyLibrary
module MyModule = 
     let x = 1
like image 82
Eugene Fotin Avatar answered Oct 15 '22 12:10

Eugene Fotin