I do no开发者_如何学Ct find a way to compile a simple file (.fs) to a .exe. I tried this example and it does not work:
In the file dolphin.fs:
let longBeaked = "Delphinus capensis" let shortBeaked = "Delphinus delphis" let dolphins = [ longBeaked; shortBeaked ] printfn "Known Dolphins: %A" dolphins
You can now compile this code to an EXE as shown here:
C:\fsharp> fsc dolphins.fs C:\fsharp> dir dolphins.exe
But when I do this an error occurs on the ":" from "C:\fsharp"
This seems a bit wrong - aside from the fact that you're not supposed to type the first bit (as explained by svick), you probably also need to specify the full path to the F# compiler. If you're using F# that comes with Visual Studio 2010, then you need:
"C:\Program Files (x86)\Microsoft F#\v4.0\Fsc.exe" dolphins.fs
If you're using standalone installation of F#, then you'll need to locate the F# compiler somewhere else (probably in "Program Files (x86)\FSharp-2.0.0.0", but I'm not exactly sure). Also, I'm not sure what is the dir
command supposed to do. To execute the compiled application (once it is compiled), you can just type:
doplhins.exe
You're not supposed to type the whole line. The C:\fsharp>
part represents the command line prompt. You should just type fsc dolhins.fs
and then dir dolphins.exe
.
The error messages sound like you're typing command-prompt commands into F# interactive.
Try opening the "Visual Studio Command Prompt" from your start menu, changing to the right directory, and typing your commands there.
Alternately, create a new F# Application project in Visual Studio, add your .fs file to the project, and build it.
精彩评论