4
votes

The following F# fragment seems to be valid only if compiled in ML compatibility mode (run it here):

   let i = (1 lxor 5)

However I can't compile it in a trivial project in Visual Studio 2012 or using fsc.exe from the command line. I get the error:

error FS0039: The value or constructor 'lxor' is not defined

Reading the F# spec it says

Although F# reserves several OCaml keywords for future use, the /mlcompatibility option enables the use of these keywords as identifiers.

It then lists lxor as one such operator. So I tried the command line fsc.exe Program.fs --mlcompatibility (version 11.0.60610.1), but it stil get the same error.

The documentation for fsc.exe seems to indicate that the mlcompatbility option only ignores warnings. I didn't see any other relevant options in fsc's documentation or project options in VS to enable compatibility.

All of the other SO questions about F#/ML compatibility seem to be related to which language constructs can be used, but all I'm looking for is how to actually compile in compatibility mode. Do I have to open a specific namespace, reference another assembly, or do something else?

Update

I have also tried using the open source compiler fsharpc (F# 3.0) on Mono on Ubuntu 13.04. The result is the same as fsc.

2
I suspect this is a regression as whatever version rextester is using seems to compile fine. Rextester is using 11.0.50727.1 against your 11.0.60610. Maybe email [email protected] with a bug report? - John Palmer
@JohnPalmer I will consider it if no one is able to provide an answer. - Mike Zboray

2 Answers

3
votes

The --mlcompatibility option only turns off warnings, so this looks like a regression. YOu can verify this by searching the source for all references to mlcompatibility here https://github.com/fsharp/fsharp/search?q=mlCompatibility&type=Code.

2
votes

When calling fsc (fsharpc on non-Windows systems), the compiler options go before the source filenames. So the correct way to call it would be something like:

fsc -o:MyProgram.exe --mlcompatibility Program.fs

When compiling with Visual Studio, you can go into the project's properties and add --mlcompatibility to the Other flags box:

Demonstrating how to add the 'mlcompatibility' flag to an F# project