f#-interactive

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

爷,独闯天下 提交于 2019-11-28 00:41:38
问题 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)] 回答1: Your problem is that you are mixing Array s and F# List s ( *type

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

若如初见. 提交于 2019-11-27 22:04:29
问题 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. 回答1: 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

F# - Keep F# interactive from posting output

佐手、 提交于 2019-11-27 18:00:14
问题 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

F#, namespaces, modules, fs and fsx

我们两清 提交于 2019-11-27 17:11:53
问题 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

How do I customize output of a custom type using printf?

左心房为你撑大大i 提交于 2019-11-27 14:35:08
I've read through a good chunk of Expert F# and am working on building an actual application. While debugging, I've grown accustomed to passing fsi commands like this to make things legible in the repl window: fsi.AddPrinter(fun (x : myType) -> myType.ToString()) I would like to extend this to work with the printf formatter, so I could type e.g. printf "%A" instanceOfMyType and control the output for a custom type. The book implies that this can be done (p 93, "Generic structural formatting can be extended to work with any user-defined data types, a topic covered on the F# website"), but I

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

喜你入骨 提交于 2019-11-27 01:41:59
问题 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?