f#

F# static methods editor colors in VS 2019

半腔热情 提交于 2021-01-29 04:35:06
问题 I am using VS 2019 with a black background editor. The List, Seq etc. methods are black and I cannot see them. Please see the attached image. What is the setting that controls the color of these methods? There is a setting 'Symbol-Static' (under Options -> Fonts and Colors -> Show Settings for: Text Editor) but Item foreground and background are disabled. The extension of the file is fsx. Thanks 回答1: You can set the color under Text Editor | Fonts and Colors: F# Functions / Methods. By the

How to get the position of the row with some key from a Deedle Frame<DateTime,_>?

大城市里の小女人 提交于 2021-01-29 02:49:11
问题 By position I mean: let position:int = positionForKey frame key let row = Frame.take positionForKey |> frame.takeLast 1 Then, row should be a Frame with only one row, whose key is key . What I don't know is how to achieve positionForKey . One idea that should work but I don't know if it's the best way of doing it would be to create another Series via Series.scanValues and let the values be the positions, but I think there oughts to be a more elegant way of doing it. The implementation via

How to get the position of the row with some key from a Deedle Frame<DateTime,_>?

大兔子大兔子 提交于 2021-01-29 02:45:53
问题 By position I mean: let position:int = positionForKey frame key let row = Frame.take positionForKey |> frame.takeLast 1 Then, row should be a Frame with only one row, whose key is key . What I don't know is how to achieve positionForKey . One idea that should work but I don't know if it's the best way of doing it would be to create another Series via Series.scanValues and let the values be the positions, but I think there oughts to be a more elegant way of doing it. The implementation via

Projecting results from MongoDb Find in F#

人走茶凉 提交于 2021-01-28 21:50:56
问题 I'm trying to query MongoDB using MongoDB.Driver and return a partial result using mongo projection. I've figured out how to query without projection, but not a partial result. This is my function for finding results: let Find<'a> collectionName (filterDefinition: FilterDefinition<'a>) = let collection = database.GetCollection<'a> collectionName collection.Find(filterDefinition).ToEnumerable() |> List.ofSeq This is an example of how I call it: let findByIdFilter id = Builders<MyModel>.Filter

Why does the weak reference not get collected in this simple F# example?

落花浮王杯 提交于 2021-01-28 08:12:04
问题 open System let WeakReferenceExample() = let mutable obj = new Object(); let weak = new WeakReference(obj); GC.Collect(); Console.WriteLine("IsAlive: {0}\nobj <> null is {1}\n---", weak.IsAlive, obj <> null); obj <- null; GC.Collect(); Console.WriteLine("IsAlive: {0}", weak.IsAlive); WeakReferenceExample() Console.ReadKey() Translated from the Rx In Action book sample. The above when run gives the following output which is different than what I get when I compile it in C# and run it. IsAlive:

F# Generic constraint to have one generic type inherit from another

半世苍凉 提交于 2021-01-27 20:10:04
问题 In C# it is straightforward to define a generic class when one generic parameter inherits from another, e.g.: public class MyClass<TClass, TInterface> where TClass : class, TInterface { } This is used to "force" the class TClass to implement the interface TInterface . I want to do the same in F# and surprisingly it does not seem to work. For example, the following code: type Startup<'S, 'I when 'I : not struct and 'S : not struct and 'S :> 'I>() = member _.x = 0 results in FS0663 - This type

Cooperative cancellation in F# with cancel continuation

自古美人都是妖i 提交于 2021-01-27 17:50:31
问题 Probably I have here 2 questions instead of one, but anyway. I'm implementing cooperative cancellation as here suggested. Here is my test code: type Async with static member Isolate(f : CancellationToken -> Async<'T>) : Async<'T> = async { let! ct = Async.CancellationToken let isolatedTask = Async.StartAsTask(f ct) return! Async.AwaitTask isolatedTask } let testLoop (ct: CancellationToken) = async { let rec next ix = if ct.IsCancellationRequested then () else printf "%i.." ix Thread.Sleep 10

How to extend a JS class in fable

爷,独闯天下 提交于 2021-01-27 16:10:23
问题 Given a class defined in an external JS library (let's call it Foo) then I'd like to extend in F# type bar() = inherits Foo ... However I can' only find examples of how to integrate with functions and [<Import("Foo", from="my-module")>] let Foo = JsNative will of course not let me derive Bar from Foo. So how Do I do that 回答1: The Import attribute can be used on a type declaration. e.g. [<Import("Foo", from="my-module")>] type Foo() = class end type Bar() = inherit Foo() You can then also

How to extend a JS class in fable

橙三吉。 提交于 2021-01-27 15:40:25
问题 Given a class defined in an external JS library (let's call it Foo) then I'd like to extend in F# type bar() = inherits Foo ... However I can' only find examples of how to integrate with functions and [<Import("Foo", from="my-module")>] let Foo = JsNative will of course not let me derive Bar from Foo. So how Do I do that 回答1: The Import attribute can be used on a type declaration. e.g. [<Import("Foo", from="my-module")>] type Foo() = class end type Bar() = inherit Foo() You can then also

How do I implement a method with a variable number of arguments?

☆樱花仙子☆ 提交于 2021-01-27 12:05:09
问题 How do I implement a method with a variable number of arguments? In C#, we can use the params keyword: public class MyClass { public static void UseParams(params int[] list) { for (int i = 0; i < list.Length; i++) { Console.Write(list[i] + " "); } Console.WriteLine(); } } So how can I do this in F#? type MyClass() = member this.SomeMethod(params (args:string array)) = () I receive the following error from the code above: The pattern discriminator 'params' is not defined 回答1: You can use