I am confused about the difference between referencing fsharp.charting.gtk in interactive and compile mode. The following code
#load "FSharp.Charting.Gtk.2.1.0/lib/net45/FSharp.Charting.Gtk.fsx"
open FSharp.Charting;;
Chart.Line [ for x in 0 .. 10 -> x, x*x ];;
produces a graph as expected in interactive mode with fsharpi, and I can compile it without errors using fsharpc but running it with mono gives the error:
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'FSharp.Charting.Gtk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null'
I realize that '#load' is for interactive mode, but I have not been able to discover its correct replacement for compile mode. I'm on osx v. 11.5.2 with an Apple M1 chip. Any help would be much appreciated. Thanks.
#load
is an F# interactive-only directive. It allows you to "load in" another F# script into the current interactive session. You seem to have discovered that paket can generate these load scripts for you, which allow you to include a package into an interactive session.*To include a package in a compiled assembly, you're going to need to add it as a reference to your project (.fsproj). Since you're using paket, you can add it like this:
dotnet paket add FSharp.Charting.Gtk
. You won't need the#load
directive in the compiled code.For more information, take a look at the package's NuGet page, which tells you the various ways to add a package to a project.
* Nowadays with F# 5, you don't actually need those paket load scripts anymore in FSI; you can now do:
#r: "nuget: FSharp.Charting.Gtk
(see How to use nuget install package for F# script without a solution?).