f#

F# can't catch TimeoutException

戏子无情 提交于 2020-01-05 07:44:08
问题 My question is really simple. Please take a look at screenshot: How could that happen? I explicitly put call to Async.RunSyncronously into try ... with . 回答1: try/with in F# async workflows do not map directly to CLR protected blocks - instead if exception is raised in user code, library code will catch it and re-route to the nearest error continuation (which can be i.e with block , finally block , custom error continuation supplied in Async.StartWithContinuations etc...). This has a

How to extract data from iterating a sequence

前提是你 提交于 2020-01-05 06:15:24
问题 csvData1 contains the data in a .csv file. I've created a sequence out of just two of the columns in the spreadsheet ("GIC-ID", "COVERAGE DESCRIPTION") let mappedSeq1 = seq { for csvRow in csvData1 do yield (csvRow.[2], csvRow.[5]) } Looking in the Visual Studio debugger x winds up being a System.Tuple<string,string> . for x in mappedSeq1 do printfn "%A" x printfn "%A" x.ToString Here is the result of executing for x in mappedSeq1 ("GIC-ID", "COVERAGE DESCRIPTION") <fun:main@28> I am having

How to extract data from iterating a sequence

本小妞迷上赌 提交于 2020-01-05 06:15:13
问题 csvData1 contains the data in a .csv file. I've created a sequence out of just two of the columns in the spreadsheet ("GIC-ID", "COVERAGE DESCRIPTION") let mappedSeq1 = seq { for csvRow in csvData1 do yield (csvRow.[2], csvRow.[5]) } Looking in the Visual Studio debugger x winds up being a System.Tuple<string,string> . for x in mappedSeq1 do printfn "%A" x printfn "%A" x.ToString Here is the result of executing for x in mappedSeq1 ("GIC-ID", "COVERAGE DESCRIPTION") <fun:main@28> I am having

Using Microsoft.FSharpLu to serialize JSON to a stream

无人久伴 提交于 2020-01-05 05:48:14
问题 I've been using the Newtonsoft.Json and Newtonsoft.Json.Fsharp libraries to create a new JSON serializer and stream to a file. I like the ability to stream to a file because I'm handling large files and, prior to streaming, often ran into memory issues. I stream with a simple fx: open Newtonsoft.Json open Newtonsoft.Json.FSharp open System.IO let writeToJson (path: string) (obj: 'a) : unit = let serialized = JsonConvert.SerializeObject(obj) let fileStream = new StreamWriter(path) let

F# How to Percentile Rank An Array of Doubles?

霸气de小男生 提交于 2020-01-05 04:54:15
问题 I am trying to take a numeric array in F#, and rank all the elements so that ties get the same rank. Basically I'm trying to replicate the algorithm I have below in C#, but just for an array of doubles. Help? rankMatchNum = 0; rankMatchSum = 0; previousScore = -999999999; for (int i = 0; i < factorStocks.Count; i++) { //The 1st time through it won't ever match the previous score... if (factorStocks[i].factors[factorName + "_R"] == previousScore) { rankMatchNum = rankMatchNum + 1; //The count

Deedle - what's the schema format for readCsv

陌路散爱 提交于 2020-01-05 04:39:05
问题 I was using Deedle in F# to read a txt file (no header) to data frame, and cannot find any example about how to specify the schema. let df= Frame.ReadCsv(datafile, separators="\t", hasHeaders=false, schema=schema) I tried to give a string with names separated by ',', but seems don't work. let schema = @"name, age, address"; I did some search on the doc, but only find following - don't know where I can find the info. :( schema - A string that specifies CSV schema. See the documentation for

How to add a local environment to a process in .NET?

徘徊边缘 提交于 2020-01-05 04:10:13
问题 To compile a Cuda kernel from the command line, two things are necessary. The first is to run the vsvars batch file like so: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat" The second is to actually invoke the compiler: "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env --cl-version 2015 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64"

Should one wrap type providers containing values that have side effects inside a class?

廉价感情. 提交于 2020-01-05 02:32:25
问题 I am trying to implement in my code the excellent advice in the F# coding conventions page https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/conventions. The section Use classes to contain values that have side effects is particularly interesting. It says There are many times when initializing a value can have side effects, such as instantiating a context to a database or other remote resource. It is tempting to initialize such things in a module and use it in subsequent functions.

protected virtual methods in f#

余生颓废 提交于 2020-01-05 01:11:08
问题 F# does not support the definition of protected methods. Here it is explained why F# replaces virtual methods with abstract methods defined in abstract classes (see here). I was wondering if there is a way to prevent access to abstract methods from outside the derived classes at all. 回答1: Like Patryk Ćwiek, I also don't think it's possible, but here's one alternative: From Design Patterns we know that we should favour Composition over Inheritance . In my experience, everything you can do with

Generic reply from agent/mailboxprocessor?

喜夏-厌秋 提交于 2020-01-04 14:09:17
问题 I currently have an agent that does heavy data processing by constantly posting "work" messages to itself. Sometimes clients to this agent wants to interrupt this processing to access the data in a safe manner. For this I thought that posting an async to the agent that the agent can run whenever it's in a safe state would be nice. This works fine and the message looks like this: type Message = |Sync of Async<unit>*AsyncReplyChannel<unit> And the agent processing simply becomes: match mailbox