#load a package in F# interactive (FSharpChart.fsx)

♀尐吖头ヾ 提交于 2019-12-13 14:28:49

问题


Hi i'm a noob and asking this newbie question, please forgive me.

I've installed successfully FSharpChart in my local directory

...
Added package 'MSDN.FSharpChart.dll.0.60.0' to folder 'C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Expert in F\packages'
Added package 'MSDN.FSharpChart.dll.0.60.0' to 'packages.config'
Successfully installed 'MSDN.FSharpChart.dll 0.60.0' to Expert in F

now, if i do

#load "FSharpChart.fsx";;
  ^^^^^^^^^^^^^^^^^^^^^^^

stdin(4,1): error FS0078: Unable to find the file 'FSharpChart.fsx' in any of
 C:\Users\Fagui\AppData\Local\Temp

additional info:

inside this folder, i see a nupkg file, and a lib directory Inside the lib directory, there is a dll, and a pdf file, but i don't see any .fsx file.

basically, F# has installed the package in the active folder for the current project, and F#interactive is in another folder ?? bit strange ?

should i install another time the package ? or what is the way around it ?

thanks

UPDATE: i don't know why, but apparently when i installed the FSharpChart package, I only got the dll, no fsx file i managed to load it doing

#I @"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Expert in F"
#r @"packages\MSDN.FSharpChart.dll.0.60\lib\MSDN.FSharpChart.dll";;

unfortunately, typing the script in F# interactive

open MSDN.FSharp.Charting
let rnd = System.Random()
let rand() = rnd.NextDouble()
let randomPoints = [for i in 0 .. 1000 -> 10.0 * rand(), 10.0 * rand()]
randomPoints |> FSharpChart.Point;;

doesn't yield any chart, but just returns a list

val rnd : Random
val rand : unit -> float
val randomPoints : (float * float) list =
  [(9.765916457, 2.272289941); (0.8211438594, 1.625466995);
   ...
   (7.783786034, 7.572208311); (6.497914692, 3.66987128); ...]
val it : ChartTypes.PointChart

this may be due to the fact that the library is not supported anymore, and that i should use a newer library like Thomas Petricek indicated.

So, i did manage to install FSharp.Charting instead

let rnd = System.Random()
let rand() = rnd.NextDouble()
let randomPoints = [for i in 0 .. 1000 -> 10.0 * rand(), 10.0 * rand()]
randomPoints |> Chart.Point;;

and it did work


回答1:


There is a newer version of the FSharpChart.fsx library which is called F# Charting, so first of all, I would recommend using this newer library instead (the API is quite similar, but F# Charting has a number of improvements).

The documentation for F# Charting also has a detailed page on referencing the library.

Typically, when you reference the library using NuGet, you'll need to specify relative reference:

// On Mac OSX use packages/FSharp.Charting.Gtk.0.90.13/FSharp.Charting.Gtk.fsx
#load "packages/FSharp.Charting.0.90.13/FSharp.Charting.fsx"

Where 0.90.13 is the version of the library that you got from NuGet (you may need to check the folder name - the path references in #load are relative to the place where your script lives).




回答2:


Yes, F# Interactive is independent of the current project.

Use:

#load @"C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Expert in F\packages\FSharpChart.fsx";;

Also you can use the #I directive if you need to reference assemblies of a specific folder, see the reference.



来源:https://stackoverflow.com/questions/34482491/load-a-package-in-f-interactive-fsharpchart-fsx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!