William Owens
William Owens

Reputation: 31

Code compiles with netcore but will not compile using mono

I'm running Ubuntu 18.04 LTS, using mono version 5.18.0.2140, and my code won't compile under mono while it does compile if I use netcore with VS Code. However, I'm required to use mono for this assignment, so I'm not sure what's going wrong. The command I'm using is:

fsharpc --nologo chessApp.fsx && mono chessApp.exe

The error happens in this part of the code (from this line and down, full gist at the bottom):

let playerOne = Chess.Human(Color.White) // Here
let playerTwo = Chess.Human(Color.Black) // Here

let game = new Chess.Game()
game.run(playerOne, playerTwo, board, pieces) // and here

The error I'm getting is the following:

 chessApp.fsx(28,17): The object constructor 'Human' takes 0 argument(s) but is here given 1. The requried signature is 'new : unit -> Human'.

 chessApp.fsx(29,17): The object constructor 'Human' takes 0 argument(s) but is here given 1. The requried signature is 'new : unit -> Human'.

 chessApp.fsx(31,1): This value is not a function and cannot be applied.

I don't get these errors using VS Code. It works there. For example, Human does take 1 argument netcore on VS Code recognizes that but mono does not. In order to not make this question longer than it has to be, I've uploaded the code to a gist right here.

Upvotes: 2

Views: 105

Answers (1)

Tomas Petricek
Tomas Petricek

Reputation: 243041

I tried reproducing this by running the compiler from command line on Windows. There are two minor errors in your fsx source file. First, you are opening a wrong namespace:

#r "chess.dll"
#r "pieces.dll"

open Chess
open Pieces // <- This should be open 'Piece'

Second, the pieces collection needs to be a list, not an array:

let pieces =
   [ king (White) :> chessPiece
     rook (White) :> chessPiece
     king (Black) :> chessPiece
     rook (Black) :> chessPiece ]

With these two changes, I was able to compile everything:

fsharpc --target:library chess.fs
fsharpc --target:library -r:chess.dll pieces.fs
fsharpc chessApp.fsx

Note that you need --target:library to indicate that this should build a dll file and also -r:chess.dll for the second file to tell it that it needs to reference the first dll.

It would be a lot easier if you referenced the two other files as source files using #load rather than as compiled files using #r:

#load "chess.fs"
#load "pieces.fs"

Then you can compile the whole thing just by running fsharpc chessApp.fsx and you'll get a single stand-alone executable.

Upvotes: 2

Related Questions