Error in Mono Compiler: Files in libraries or applications with multiple files should start with a namespace or module declaration

I am trying to compile this example in mono on ubuntu.

However i get an error

wingsit@wingsit-laptop:~/MyFS/kitty$ fsc.exe -o kitty.exe  kittyAst.fs kittyParser.fs kittyLexer.fs main.fs 
Microsoft (R) F# 2.0 Compiler build 2.0.0.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

/home/wingsit/MyFS/kitty/kittyAst.fs(1,1): error FS0222: Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'

/home/wingsit/MyFS/kitty/kittyParser.fs(2,1): error FS0222: Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'

/home/wingsit/MyFS/kitty/kittyLexer.fsl(2,1): error FS0222: Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'
wingsit@wingsit-laptop:~/MyFS/kitty$ 

I am new to F #. Is there something obvious I'm missing?

+3
source share
4 answers

As Brian and Scott pointed out, you need to enclose the file in a namespace declaration or in a module. Just adding namespace SomeNamespacemay not work if you have a top-level binding letin the file (as it should be in some module). The following is not valid:

namespace SomeNamespace
let foo a b = a + b   // Top-level functions not allowed in a namespace

, namespace module , module ( , ):

namespace SomeNamespace
module FooFunctions =     
  let foo a b = a + b

, , , ( F # PascalCase , ):

// 'main.fs' would be compiled as:
module Main
let foo a b = a + b
+4

, ,

module theCurrentFileName

.fs.

, , .

+2

- , F #, .

, , , namespace SomeNamespace , . ubuntu.

0

Old question, but I reached it for the same problem, and I want to add a tooltip for the module in F # 3.

In multi-file applications, you do not need to use a namespace, but you should use a module

Top-level module declaration declared this way (without equal sign =)

 module module_name
 //Not
 module module_name =

Local modules in the same file, use "=" Example:

 module toplevel        // top level module without "="

 module module1 =      // local module with "="
   let square x = x*x

 module module2 =
   let doubleit x = 2*x
  • You do not need to specify declarations in the top-level module.
  • You need to postpone all ads in local modules.
0
source

Source: https://habr.com/ru/post/1742053/


All Articles