2

this is probably a simple question, but I post it as a question since I can not figure it out. There might be a duplicate somewhere here on stackoverflow, but I could not find any. I am writing code on ubuntu with visual studio code.

This is the content of my test.fs file:

open System 
(*print*)

let main() = 
    Console.WriteLine("hello")

main()

I wanted to compile it on the terminal. I know that the compiler is there, because I can run an interactive F# session from it. I get this error For each of the lines (4)

error: expected class or object definition

That lead me to believe that it was a namespace/package problem, which I believe is a module in F#. However, I found this (https://learn.microsoft.com/en-us/dotnet/articles/fsharp/language-reference/modules): "a code file does not begin with a top-level module declaration or a namespace declaration, the whole contents of the file, including any local modules, becomes part of an implicitly created top-level module that has the same name as the file, without the extension, with the first letter converted to uppercase."

Thus, it should not be necessary to declare it as a module. However, I tried that as well, without any success.

So can someone help me with what could be the error cause?

and also further help me with how to get this compiled correctly?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
stian
  • 1,947
  • 5
  • 25
  • 47
  • If you dont get help here; you could try askubuntu too. – GhostCat Sep 26 '16 at 11:57
  • Of Interest: Did you know that that you can do F# (using mono) with Ubuntu bash on Windows 10 without using a Virtual Machine. See: [Bash on Ubuntu on Windows](https://msdn.microsoft.com/en-us/commandline/wsl/about). – Guy Coder Sep 26 '16 at 15:57

1 Answers1

4

You appear to have called the scala compiler which was called fsc before fsharp - see for example here error: expected class or object definition for a question with that error message which is not an error message from the F# compiler.

On linux the F# compiler is called fsharpc on many distros to avoid this problem.

Community
  • 1
  • 1
John Palmer
  • 25,356
  • 3
  • 48
  • 67