f#

Map on Map<'a, int>

别来无恙 提交于 2019-12-10 21:24:48
问题 I have the following type : type MultiSet<'a when 'a: comparison> = MSet of Map<'a, int> and I now want to declare af map function for this type with the signature : ('a -> 'b) -> Multiset<'a> -> Multiset<'b> when 'a : comparison and 'b : comparison I have tried : let map m ms = match ms with | MSet s -> MSet ( Map.map (fun key value -> m key) s ) But that it has the signature : ('a -> int) -> Multiset<'a> -> Multiset<'a> when 'a : comparison What is wrong with my implementation when I want

F# is running very slow since last round of Windows updates

蓝咒 提交于 2019-12-10 21:19:22
问题 I recently installed the latest rounds of Windows updates, including the .NET 4.0 updates and the Visual Studio updates (but not VS2010 SP1). Since then, my F# compiler has been running really, really slow. I thought it might be this problem with crl.microsoft.com, but it turns out not to be. Also, I think mscorsvw.exe has completed running. (I forget the command to force it, but it doesn't kick in, even when the machine is idle.) Also: The F# compiler is producing correctly running code,

Deploy WebSharper.Suave web application to Heroku

岁酱吖の 提交于 2019-12-10 21:09:42
问题 I can not understand what I need to change to make it. I created a demo project from this blogpost with app.json and Procfile: web: fsharpi-heroku WebsahrperSuaveHerokuExample1.sln Next, I tried to deploy it to Heroku in accordance with these recommendations: heroku create websahrper-with-suave-example --buildpack https://github.com/SuaveIO/mono-script-buildpack.git heroku git:remote -a websahrper-with-suave-example git push heroku master There was an error in Heroku when building the project

How to define a record field as an array in f#?

耗尽温柔 提交于 2019-12-10 21:08:21
问题 I want to create a record field of type byte array with 8 elements but couldn't figure out the correct syntax. I did something like: let dataRecord = { id : int data : byte array } let dataValues : byte array = Array.zeroCreate 8 let myArray = { id = 0; data = dataValues } Can it be done in the record definition? How? My example, above, seemed to work but I don't know if it is safe or the best or most correct way. 回答1: There's nothing wrong with what you're currently doing (other than that

Why this F# function runs only once? I call twice and it runs only once

霸气de小男生 提交于 2019-12-10 20:49:38
问题 I wrote the following code to test some MonteCarlo code in F#. My problem is I only see the random numbers and the "oi" once in my console. I call two times the oneRun function, but it looks that it only runs once. Here is the code: let genRandomNumbers count = let rnd = System.Random() printf "oi " List.init count (fun _ -> rnd.NextDouble ()) let oneRun = let numberofClicks = 0 let randomNumber = genRandomNumbers 50 let action numberofClicks random = if random <= 0.10 then numberofClicks+1

'base' values may only be used to make direct calls to the base implementations of overridden members

孤街醉人 提交于 2019-12-10 20:43:11
问题 Why can't I call the base implementation of f here: type Base = abstract f : int -> int -> int default this.f (x : int) (y : int) : int = x + y type Derived = inherit Base override this.f (x : int) (y : int) : int = base.f -x -y The call to base.f elicits this compiler error: error FS0419: 'base' values may only be used to make direct calls to the base implementations of overridden members If I change f to take a single argument then it compiles. Presumably this is something to do with

404 response appended to webapi response

你。 提交于 2019-12-10 20:14:58
问题 I have managed to get TWO responses for a single web request: My webapi response ( a simple string with 200 status code) a 404, from what looks like a static file handler Screenshot from chrome: My setup is: F# Mono on Ubuntu 15.10 xsp4 as the web server Owin as the routing engine As you can see from the screenshot the correct response is printed (sometimes - sigh) on the first line of the browser's reponse, and then immediately followed on the page by the standard 404 page. Startup code:

F# odd pattern matching issues

拥有回忆 提交于 2019-12-10 20:12:38
问题 While writing some code yesterday, I ran into two odd problems, which neither me nor my functional programming oriented friend could figure out. We have looked at it for quite some time, and researched it on the net, but we were not able to find any answers anywhere, so here goes: The issue is that in this code: First weird problem: let outer1 (bs : byte array) = let rec inner (bs : byte array) (bacc : byte array) (i : int) = match i with | bs.Length -> bacc // <--- Error: bs is not

Reference a record from within itself during construction

限于喜欢 提交于 2019-12-10 20:10:08
问题 I am trying to create a record which uses one of the previously defined fields to calculate the value of another, within the same constructor. e.g. myRecordType = {Foo:int; Bar:int[]} myRecord = {Foo = 5; Bar = Array.init Foo (fun i -> i)} When I try this it doesn't recognise Foo as already existing. I also can't reference Foo using myRecord.Foo , but that makes sense since myRecord hasn't been constructed yet. However I would've thought that Foo and Bar would be in the same scope, so Bar

Why F# quotation cannot contains struct?

眉间皱痕 提交于 2019-12-10 20:04:24
问题 I would like to define a struct, which contains some member methods. And I want to use [<ReflectedDefinition>] to mark that struct member method. But the compiler tells me it is wrong. First, see this piece of code: type Int4 = val mutable x : int val mutable y : int val mutable z : int val mutable w : int [<ReflectedDefinition>] new (x, y, z, w) = { x = x; y = y; z = z; w = w } [<ReflectedDefinition>] member this.Add(a:int) = this.x <- this.x + a this.y <- this.y + a this.z <- this.z + a