f#

Type level number arithmetic

两盒软妹~` 提交于 2019-12-11 02:33:52
问题 I'm playing around with F#'s type inferrer. Trying to get type level natural number working. Here's the part that I managed to get working type Zero = Zero type Succ<'a> = None type True = True type False = False type IsZero = | IsZero static member instance (IsZero, _ : Succ<'a>, _) = fun () -> False static member instance (IsZero, _ : Zero, _) = fun () -> True module TypeArithmetic = let inline zero x = (Inline.instance (IsZero, x) : unit -> 'a)() let dec (_ : Succ<'a>) = Unchecked

F#: How to Call a function with Argument Byref Int

隐身守侯 提交于 2019-12-11 02:26:52
问题 I have this code: let sumfunc(n: int byref) = let mutable s = 0 while n >= 1 do s <- n + (n-1) n <- n-1 printfn "%i" s sumfunc 6 I get the error: (8,10): error FS0001: This expression was expected to have type 'byref<int>' but here has type 'int' So from that I can tell what the problem is but I just dont know how to solve it. I guess I need to specify the number 6 to be a byref<int> somehow. I just dont know how. My main goal here is to make n or the function argument mutable so I can change

seq<obj> versus seq<float> in F#

妖精的绣舞 提交于 2019-12-11 02:25:14
问题 I have the following method: member this.addColumnWithHeading heading column = this.addColumn (seq { yield heading; yield! (column |> Seq.map string)}) which takes a string heading and any sequence (which is compiled to seq in this case), creates a sequence of strings and calls another method with this data. However, it doesn't work with column being a sequence of floats: Error 1 The type 'obj' does not match the type 'float' C:\Users\ga1009\Documents\PhD\cpp\pmi\fsharp\pmi\Program.fs 138 How

using F# XMLProvider for large nested xml file

為{幸葍}努か 提交于 2019-12-11 02:17:54
问题 I have a large deeply nested xml file, over 200MB. I have written a streaming function in c# using linq to xml. But knowing about f# type provider I am tempted to use the XMLTypeProvider but it may load the entire xml into memory. Is there any way to optimize it to lazy load in the provider and get the benefit of dot. Thanks 来源: https://stackoverflow.com/questions/37135965/using-f-xmlprovider-for-large-nested-xml-file

Any way to check-in into TFS from FAKE build target?

谁说我不能喝 提交于 2019-12-11 02:14:28
问题 I'm trying to create FAKE(F# Make) build target that will update AssemblyInfo files in my project after sucsess build. Version info files are stored in TFS CVS, so I need to checkin updated files to TFS from FAKE build task. Using TFS 2010, call FAKE from custom activity. My flow is: - ... cleanup, call build target - Update AssemblyInfo files - Check-in files to TFS Faced with check-in to TFS issues... Is there any way to check-in to TFS from FAKE (F# Make) target? 回答1: Yes, but this will

How to run F# Silverlight Library project holding xUnit.net Contrib based unit tests?

非 Y 不嫁゛ 提交于 2019-12-11 02:13:37
问题 I am unaware of any project templates for F# Silverlight 4 unit tests (I searched Online for templates through Add Project), so I am using the standard F# Silverlight Library project to hold my unit tests (which are just file links to the main unit test project files). I am using xUnit.net Contrib for Silverlight. So everything compiles but I don't know how to run the tests! TestDriven.NET works for my normal unit test project but not this Silverlight unit test project. I tried to use the

Adding code in constructor with alternative class syntax

孤街醉人 提交于 2019-12-11 02:11:13
问题 type Foo = class inherit Bar val _stuff : int new (stuff : int) = { inherit Bar() _stuff = stuff } end I want to add this code in above constructor: if (stuff < 0) then raise (ArgumentOutOfRangeException "Stuff must be positive.") else () How can I achieve this in F# ? 回答1: You can do this without needing any workarounds, but the placement of the initial left curly is fairly sensitive (or maybe the parser is buggy?). To do the effect first: type Foo = class inherit Bar val _stuff : int new

FParsec only parses expr between parentheses

不想你离开。 提交于 2019-12-11 02:08:29
问题 I am coding a parser (for learning pourpuses). I want it to parse constructions like let myVar be 40 plus 2 and let myVar be (40 plus 2) With no problems... but my parser does not "understand" the former. It sees the 40 and thinks "well, it's a Literal Numeric 40 ". When I put parentheses, my parser works great. I am having a hard time to understand why. Parser: type value = | Boolean of bool | Numeric of float | String of string type arithmetic = Sum | Sub | Mul | Div | Pow type logic = And

Dependency Property in F#

梦想的初衷 提交于 2019-12-11 02:06:28
问题 I have an MVVM app written in F# and one of the main problems which I have faced was closing of modal dialogs. I decided to subscribe to an viewmodel's RequestedClose event in view, but problem of DialogResult still remained. So, I decided to bind DialogResult to viewmodel's property, but soon I realized that DialogResult is not a DependencyProperty. Eventually I tried to implement this accepted answer. But I couldn't get it to work... Here's my code: type DialogCloser() = static let

List comprehensions with float iterator in F#

风流意气都作罢 提交于 2019-12-11 02:00:55
问题 Consider the following code: let dl = 9.5 / 11. let min = 21.5 + dl let max = 40.5 - dl let a = [ for z in min .. dl .. max -> z ] // should have 21 elements let b = a.Length "a" should have 21 elements but has got only 20 elements. The "max - dl" value is missing. I understand that float numbers are not precise, but I hoped that F# could work with that. If not then why F# supports List comprehensions with float iterator? To me, it is a source of bugs. Online trial: http://tryfs.net/snippets