![]() Consider the following code in a project compiled into MyAssembly.dll: // MyAssembly.fs Referencing assemblies on disk with F# interactiveĪlternatively, if you have an assembly on disk and wish to reference that in a script, you can use the #r syntax to specify an assembly. Packages like Saturn, Giraffe, WinForms are not available. There's currently a limitation for scripts that use framework references (e.g. You can specify as many package references as you like in a script. This will tell the resolution engine under the covers to also take into account the remote and/or local sources added to a script. The following example specifies a remote and a local source: #i "nuget: #i """nuget: C:\path\to\my\local\source""" You can also specify a package source with the #i command. For example, consider this script using a preview version of DiffSharp: #r "nuget: DiffSharp-lite, 1.0.0-preview-328097867" This can be handy when referencing a preview version of a package. To reference a specific version, introduce the version via a comma. If a version is not specified, the highest available non-preview package is taken. ![]() Referencing packages in F# Interactiveį# Interactive supports referencing NuGet packages with the #r "nuget:" syntax and an optional version: #r "nuget: Newtonsoft.Json" When this file is created in your machine, you can run it with dotnet fsi and see the output directly in your terminal window: dotnet fsi Script.fsxį# scripting is natively supported in Visual Studio, Visual Studio Code, and Visual Studio for Mac. For example, consider the following script called Script.fsx: let getOddSquares xs = Instead of compiling source code and then later running the compiled assembly, you can just run dotnet fsi and specify the filename of the script of F# source code, and F# interactive reads the code and executes it in real time. To support normal code editing, you can write F# scripts. F# Interactive then evaluated the code and printed the results! Scripting with F#Įvaluating code interactively in F# Interactive can be a great learning tool, but you'll quickly find that it's not as productive as writing code in a normal editor. The code's formatting is preserved, and there is a double semicolon ( ) terminating the input. Val getOddSquares : xs:int list -> int list Consider the following snippet that has been pasted into and evaluated by F# Interactive: > let getOddSquares xs = You just need to terminate your submission with a double semicolon ( ). You can reference it interactively.į# Interactive also supports multi-line input. Code is evaluated and stored in an it value.All code must be terminated with a double semicolon ( ) to be evaluated.Here is an example of an interactive session after executing dotnet fsi from the command line: Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0Ĭopyright (c) Microsoft Corporation. Executing code directly in F# Interactiveīecause F# Interactive is a REPL (read-eval-print loop), you can execute code interactively in it. NET Framework runtime, you'll need the Visual Studio Build Tools or an edition of Visual Studio installed, and invoke the FsiAn圜PU.exe command from a "Developer Command Prompt" or simply make FsiAn圜PU.exe available in the PATH environment variable.įor information about available command-line options, see F# Interactive Options. If you intend to use F# interactive under.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |