f#-interactive

How Do I Use A Variable As The Formatting String With Sprintf?

余生颓废 提交于 2019-11-29 13:14:02
I feel like a total noob for having to ask this but it's got me stumped. I set a format string like this: let fs = "This is my format test %s" Then I attempt to use it like so: let s = sprintf fs "testing" When I do so I get this error: //stdin(26,17): error FS0001: The type 'string' is not compatible with the type 'Printf.StringFormat<('a -> 'b)>' So I then tried this: let s = sprintf (Printf.StringFormat fs) "test" to which the REPL responded: //stdin(28,18): error FS1124: Multiple types exist called 'StringFormat', taking different numbers of generic parameters. Provide a type instantiation

How can I select a random value from a list using F#

落花浮王杯 提交于 2019-11-29 07:08:18
I'm new to F# and I'm trying to figure out how to return a random string value from a list/array of strings. I have a list like this: ["win8FF40", "win10Chrome45", "win7IE11"] How can I randomly select and return one item from the list above? Here is my first try: let combos = ["win8FF40";"win10Chrome45";"win7IE11"] let getrandomitem () = let rnd = System.Random() fun (combos : string[]) -> combos.[rnd.Next(combos.Length)] Your problem is that you are mixing Array s and F# List s ( *type*[] is a type notation for Array ). You could modify it like this to use lists: let getrandomitem () = let

Using NLog with F# Interactive in Visual Studio - Need documentation

拥有回忆 提交于 2019-11-29 05:11:06
I have a need to capture the input and output of F# functions when using F# Interactive. I am able to get NLog to work just fine when the program is run under Visual Studio using F5 or Ctrl-F5. Also the same methods that contain statements to output to the log work just fine and are called when invoked via F# Interactive; just nothing in the log file. I also tried the following with F# Interactive to setup references to NLog and still nothing in the log when run from F# Interactive. #I @"..\packages\NLog.2.0.0.2000\lib\net40" #r @"NLog.dll" And I even found this which led me to try each of

Need help regarding Async and fsi

梦想与她 提交于 2019-11-29 05:06:35
I'd like to write some code that runs a sequence of F# scripts (.fsx). The thing is that I could have literally hundreds of scripts and if I do that: let shellExecute program args = let startInfo = new ProcessStartInfo() do startInfo.FileName <- program do startInfo.Arguments <- args do startInfo.UseShellExecute <- true do startInfo.WindowStyle <- ProcessWindowStyle.Hidden //do printfn "%s" startInfo.Arguments let proc = Process.Start(startInfo) () scripts |> Seq.iter (shellExecute "fsi") it could stress too much my 2GB system. Anyway, I'd like to run scripts by batch of n, which seems also a

F# - Keep F# interactive from posting output

泪湿孤枕 提交于 2019-11-29 04:01:36
I'm working with F# interactive and I'm computing some large lists and arrays and I'd rather not have the interactive window post all of that information. Is there way to suppress output? Specifically I'm developing single threaded and multithreaded algorithms and evaluating at what point does it become more efficient to change from a single threaded function to a multithreaded one. I'd like to have F# Interactive report the run time for the functions, I've been using #time, but I don't want to have to scroll way back up when it prints the large matrix of data to the screen. If there is a way

How to load external F# script file and use it in F# interactive?

ぐ巨炮叔叔 提交于 2019-11-29 03:07:02
I would like to load one or more .fsx files into the F# interactive and have all the functions defined in the .fsx files in scope so that I can directly use the functions in the console. The #load directive executes the .fsx file specified, but then I am no longer able to use those functions in the .fsx file. Any workaround for this? Thanks. I suspect that the script you are loading is not in a module which may be causing your problem. Just add module Script1 in the first script and then you can do #load "Script1.fsx" open Script1 and your functions will be accessible If you don't declare a

F#, namespaces, modules, fs and fsx

随声附和 提交于 2019-11-29 02:54:40
I'm aware of other questions about modules and namespaces in F#, but they're not helping me right now. I've got a project with Utilities.fs namespace Company.Project.Namespace module Utilities = //stuff here Functions.fs namespace Company.Project.Namespace open Utilities module Functions = //stuff here And I'm trying to test them in an fsx: #load "Utilities.fs" #load "Functions.fs" which gives me error FS0039: The namespace or module 'Utilities' is not defined when I try to send it to FSI with Alt-Enter . I've tried adding same namespace at the top of the script file, but it doesn't like that.

F# interactive - how to see all the variables defined in current session

假如想象 提交于 2019-11-29 00:01:11
问题 In F# interactive, how can I see a list of variables/functions defined in this session? Like a function whos() in python or ls() in R? Thanks. 回答1: You can probably implement this using .NET Reflection - local variables and functions are defined as static properties/methods of types in a single dynamic assembly. You can get that assembly by calling GetExecutingAssembly (in FSI itself) and then browse the types to find all suitable properties. The following is a reasonably working function for

How Do I Use A Variable As The Formatting String With Sprintf?

假装没事ソ 提交于 2019-11-28 07:08:58
问题 I feel like a total noob for having to ask this but it's got me stumped. I set a format string like this: let fs = "This is my format test %s" Then I attempt to use it like so: let s = sprintf fs "testing" When I do so I get this error: //stdin(26,17): error FS0001: The type 'string' is not compatible with the type 'Printf.StringFormat<('a -> 'b)>' So I then tried this: let s = sprintf (Printf.StringFormat fs) "test" to which the REPL responded: //stdin(28,18): error FS1124: Multiple types

F#/C# - fsx Script Files and Project References

橙三吉。 提交于 2019-11-28 07:03:27
You have a solution with one C# project in it. SomeComp.Framework is the name. You add a F# project to the solution. You reference the SomeComp.Framework project in the F# project. You insert a script file - test.fsx into the F# project. What is the correct way to reference the C# assembly in the script file? #r "SomeComp.Framework.dll" // doesn't work Is there some way to do this without hardcoding a path? Does the .fsx file get any settings/properties from being located inside a F# project? No, it does not get any settings from the project, you have to hardcode the path. (This is a scenario