f#

Drawing a random number from a discrete distribution function stored as a sequence of probabilities in F#

点点圈 提交于 2019-12-23 20:18:41
问题 There is a given sequence of floats (between 0 and 1) of finite length N which denotes a distribution function over integers 0..N-1. We are trying to draw a random number from this distribution. One way of doing it is to draw a uniform random variable in [0, 1] (float), and then calculate the inverse cumulative distribution function for that number. If the distribution was in an array, the code would look something like this: let matched distribution draw = let rec matchRest distribution draw

Plotting Deedle frame

谁说我不能喝 提交于 2019-12-23 20:14:50
问题 I have the following piece of code: let mychart = frame.GetAllSeries() |> Seq.iter(fun key value -> Chart.Line(value, Name=key) |> Chart.Combine where frame.GetAllSeries() returns a seq<KeyValuePair> . I'd like to pipe the sequence directly in a chart. I thought I could iterate through the sequence. The problem is that I can't find an idomatic way to access the key and value separately that could be plugged in directly in the lambda expression. Thanks. EDIT This works: let chart = frame

Incomplete pattern matching a tuple in F#

孤者浪人 提交于 2019-12-23 20:14:44
问题 I define a point type TimeSeriesPoint<'T> = { Time : DateTimeOffset Value : 'T } and a series type TimeSeries<'T> = TimeSeriesPoint<'T> list where I assume the points in this list are ordered by time. I am trying to zip two time series, where, in general, they will have points with the same time, but there might be some points missing in either of them. Any idea why I get a warning for incomplete pattern matches in the code below? let zip (series1 : TimeSeries<float>) (series2 : TimeSeries

Using a custom version of FSharp.Core.dll

夙愿已清 提交于 2019-12-23 19:33:34
问题 I've been poking around with the fsharp compiler source code to try to build a wp7 version of FSharp.Core (FSharp.Core for Windows Phone 7.1 and F# 3.0), and at one point I gave up and started trying to make the portable version work with wp7 instead. I added the FX_NO_STRUCTURAL_EQUALITY define to the portable-net4+sl4+wp71+win8 target framework, which seems to what's causing it to not work at runtime, and tried to replace the FSharp.Core.dll in C:\Program Files (x86)\Reference Assemblies

F# Convert 'a discriminated union to string

﹥>﹥吖頭↗ 提交于 2019-12-23 19:26:57
问题 I'm trying to convert a discriminated union to string but I don't understand why this code is not working. type 'a sampleType = | A of 'a | B of 'a let sampleTypeToString x = match x with | A (value) -> string value | B (value) -> string value This is the fsharp interactive output sampleTypeToString A(2);; Stopped due to error System.Exception: Operation could not be completed due to earlier error Successive arguments should be separated by spaces or tupled, and arguments involving function

F# computation expression for nested Boolean tests?

为君一笑 提交于 2019-12-23 19:12:59
问题 I think I've got enough understanding of F# monads (workflows) that I see a few places in my code where implementing them makes sense. For example, I've got a function with multiple nested if/thens, i.e. the function should continue only so long as the data pass certain "tests" along the way. I'm familiar with the "maybe" monad, but in all the examples that I've seen, it's coded to operate on let! bindings, which I'm not doing. I'm hoping that someone can provide me with an example of the

Statically resolved string conversion function in F#

折月煮酒 提交于 2019-12-23 19:09:58
问题 I'm trying to create a function in F# that will convert certain types to a string, but not others. The objective is so that a primitive can be passed but a complex object cannot be passed by accident. Here's what I have so far: type Conversions = static member Convert (value:int) = value.ToString() static member Convert (value:bool) = value.ToString() let inline convHelper< ^t, ^v when ^t : (static member Convert : ^v -> string) > (value:^v) = ( ^t : (static member Convert : ^v -> string)

Parsing JSON Using F# (not Serialization)

十年热恋 提交于 2019-12-23 18:32:58
问题 I am trying to build a tree (via a discriminated union type) in my F# application to represent my data generically. I researched what was available on the web and I have found things like the JavaScriptSerializer and the DataContractJsonSerializer. The problem is, I am not really serializing the data into a specific object. Here is my discriminated union: type ParameterTree = | End | Node of string * Dictionary<string, Parameter> * ParameterTree I basically want to be able to read in from a

Referencing an x64 dll file works in C# but does not work in F#

空扰寡人 提交于 2019-12-23 18:32:24
问题 I have created two brand new solutions using the latest VS 2010: C# console application F# console application I have referenced two x64 dll files: Kitware.VTK.dll and Kitware.mummy.Runtime.dll (can be downloaded here: http://www.kitware.com/products/avdownload.php ) The C# VS 2010 finds the namespace when I write using Kitware . The F# VS 2010 does not find the namespace when I write open Kitware . The x86 version works fine in F#. Any idea why is that and how to make the Kitware x64 work in

How can I use an F# discriminated union type as a TestCase attribute parameter?

懵懂的女人 提交于 2019-12-23 18:10:29
问题 I am trying to test that the return result from an F# function matches an expected discriminated union case. I am using NUnit to create the tests and it does not like the discriminated union type as a TestCase parameter. The following test case fails to compile: [<TestCase("RF000123", Iccm.CallType.Request)>] let ``callTypeFromCallNumber returns expected call type`` callNumber callType = test <@ Iccm.callTypeFromCallNumber callNumber = callType @> I expect that this is a limitation of NUnit