f#

Library for reading csv file in F#

我怕爱的太早我们不能终老 提交于 2019-12-10 16:37:08
问题 F# I am interested to read a csv file and output a List< List< string > > let readCsv (filepath:string) : string list list = //....................... input file: Quote1,Quote2,Quote3 "Hello,World","He said:""Yes""",Example Output: // Type: string list list [["Quote1";"Quote2";"Quote3"]; ["Hello,World"; "He said:"Yes"";"Example"]] Input2: 1,2,3,4,5,6 7,8,9,10,11,12 Output2: // Type: string list list [["1";"2";"3";"4";"5";"6"]; ["7";"8";"9";"10";"11";"12"]] However, some of the Nuget packages,

Using Functional Programming to compute prime numbers efficiently

半世苍凉 提交于 2019-12-10 16:33:33
问题 I'm getting acquainted with F# by going over Project Euler and solving some of the problems. Many of the early problems consist of prime numbers. After looking around I came up with the following solution: let primesL = let rec prim n sofar = seq { if (sofar |> List.forall (fun i->n%i <>0L)) then yield n yield! prim (n+1L) (n::sofar) else yield! prim (n+1L) sofar } prim 2L [] This works well, but then I generate all the prime numbers up to 2000000: let smallPrimes = primesL |> Seq.takeWhile

How do you print the resulting units using units of measure in F#?

懵懂的女人 提交于 2019-12-10 16:19:59
问题 I am beginning to learn how to use units of measure in F# but I haven't found the answer to this simple question yet. How do you print the resultant units after a calculation. I know that FSI prints them so they should be available somehow. For example: [<Measure>] type m;; [<Measure>] type s;; let d = 10<m>;; val d : int<m> = 10 let t = 2<s>;; val t : int<s> = 2 I want to do something like this: printfn "Results: %A %A" (d / t) (UOM (d / t));; "Results: 5 m/s" Thanks in advance 回答1:

How do I do convolution in F#?

雨燕双飞 提交于 2019-12-10 16:13:38
问题 I would like convolve a discrete signal with a discrete filter. The signal and filter is sequences of float in F#. The only way I can figure out how to do it is with two nested for loops and a mutable array to store the result, but it does not feel very functional. Here is how I would do it non-functional: conv = double[len(signal) + len(filter) - 1] for i = 1 to len(signal) for j = 1 to len(filter) conv[i + j] = conv[i + j] + signal(i) * filter(len(filter) - j) 回答1: Try this function: let

F# how to Window a sequence based on predicate rather than fixed length

两盒软妹~` 提交于 2019-12-10 15:57:11
问题 Given the following input sequence, I would like to generate the desired output. I know that Seq.window can be used to almost get the desired result if all the windows are a fixed length. However in this case they are not fixed legnth, I would like to start a new sequence whenever "a" is encountered. Is this possible with the standard collections library? let inputSequence = ["a"; "b"; "c"; "a"; "b"; "c"; "d"; "a"; "b"; "a"; "d"; "f"; "a"; "x"; "y"; "z"] let desiredResult = [["a"; "b"; "c";]

Custom IEnumerator in F#

廉价感情. 提交于 2019-12-10 15:55:28
问题 More F# questions. I have the implementation of a binary reader below. I want it to work like an enumerable sequence. The code below gives me the following error and I have as usual no clue how to resolve it. I have a c# implementation where I had to implement two different overrides for .Current property. I guess I have to do the same here but not sure how. As always, thanks a million in advance for your help. error FS0366: No implementation was given for Collections.IEnumerator.get_Current(

Is there any way to control AutoDetectChanges on SqlEntityConnection?

北城以北 提交于 2019-12-10 15:48:37
问题 This article provides some evidence that turning off AutoDetectChanges on your Entity Framework data context can provide a significant performance improvement when inserting large numbers of entities. context.Configuration.AutoDetectChangesEnabled = false; However, the DataContext provided by the SqlEntityConnection type provider doesn't seem to provide any way to control this setting. There's no context.Configuration property, or context.DataContext.Configuration property. There is a context

F# Query, Group Multiple Values by Single Column

与世无争的帅哥 提交于 2019-12-10 15:45:03
问题 I have an F# sql query which needs to sum two columns in each group. let financials = query{ for data in dbData do groupValBy (data.earning, data.losses) data.store into group select (group.Key, group.Sum(fun (group) -> fst group), group.Sum(fun (group) -> snd group)) } I have not been able to find any examples of how to do this, however this code compiles fine, and by every indication, it should work. However when executing I always get an exception with this message "Could not format node

F#: only do one action once for the first event, without mutability/locking?

大憨熊 提交于 2019-12-10 15:45:00
问题 I have this code that downloads a file and tells me in the console how big is the file: use webClient = new WebClient() let lockObj = new Object() let mutable firstProgressEvent = true let onProgress (progressEventArgs: DownloadProgressChangedEventArgs) = lock lockObj (fun _-> if (firstProgressEvent) then let totalSizeInMB = progressEventArgs.TotalBytesToReceive / 1000000L Console.WriteLine ("Starting download of {0}MB...", totalSizeInMB) firstProgressEvent <- false ) webClient

How are interfaces exported in Funscript

半城伤御伤魂 提交于 2019-12-10 15:43:58
问题 I've got the Funscript examples working. Now I'm trying to make something like a Funscript library which has functions (and hopefully classes!) that can be called from javascript code. But I can't see a way of accessing anything from the .js generated from Funscript. In short, how do I get Javascript to call Funscript? 回答1: Sorry but FunScript is not designed for this use case. It is designed for consuming code and data from various sources in a script rather than for exporting code as a