f#

Problem with F# Powerpack. Method not found error

Deadly 提交于 2019-12-08 17:08:09
问题 I've had F# Powerpack for a while now. It ran perfectly. But a few days before, I don't know what I did, whenever I compile my project and run it, I get an error Method not found: 'System.Object Microsoft.FSharp.Text.Parsing.Tables`1.Interpret(Microsoft.FSharp.Core.FSharpFunc`2<Microsoft.FSharp.Text.Lexing.LexBuffer`1<Char>,!0>, Microsoft.FSharp.Text.Lexing.LexBuffer`1<Char>, Int32)'. I tried on my laptop too. Then I thought, that it might be an error in my code. So I started a new project, F

How to change a dropdown in an F# Canopy UI Testing Script

早过忘川 提交于 2019-12-08 17:05:38
问题 I am really enjoying using Canopy Web Testing to test out my .NET Web Apps with F#. However the documentation is sparse. I'm looking for a hint on how to change an HTML select tag to select an element based on a value of an option. Right now, all I can manage to do is calling the click event from Canopy, and then firing press down the correct number of times in my test to get to the proper element. Of course, this means my tests all break if the number of elements in the dropdown changes.

Accessing let bound fields from static members

心已入冬 提交于 2019-12-08 16:10:24
问题 Is there any way to access let bound fields from a static member? The following gives the indicated error: type Foo(x) = let x = x static member test() = let foo = Foo(System.DateTime.Now.Month) printfn "%A" foo.x //the field, constructor or member 'x' is not defined () Whereas private explicit fields do allow access from static members: type Bar = val private x:int new(x) = { x=x } static member test() = let Bar = Bar(System.DateTime.Now.Month) printfn "%A" Bar.x () The documentation http:/

Shadowing vs. Setting value in F#

Deadly 提交于 2019-12-08 16:09:56
问题 I've been introduced that data, by default is immutable in F#. When we reassign value to some variable, what really happens is that it rebinds the value of variable, but setting a new value is different thing. Rebinding is called Shadowing whilst setting new value is impossible if we explicitly don't say that value of the variable is mutable. Can anybody explain me this concept in details? what's difference between shadowing (rebinding) by let var = "new_value" and Setting new value like var

Serializing F# Option types

邮差的信 提交于 2019-12-08 16:09:54
问题 Consider the F# fragment below: type MyType = { CrucialProperty: int OptionalProperty: string option } let first = { CrucialProperty = 500; OptionalProperty = Some("Hello")} let second = { CrucialProperty = 500; OptionalProperty = Some(null)} let third = { CrucialProperty = 500; OptionalProperty = None} I wish to do serialize this type using JSON.NET so I get the following strings respectively for the cases described above: {"CrucialProperty":500,"OptionalProperty":"Hello"} {"CrucialProperty"

Why don't F# lists have a tail pointer

拈花ヽ惹草 提交于 2019-12-08 16:05:29
问题 Or phrased another way, what kind of benefits do you get from having a basic, singly linked list with only a head pointer? The benefits of a tail pointer that I can see are: O(1) list concatenation O(1) Appending stuff to the right side of the list Both of which are rather convenient things to have, as opposed to O(n) list concatenation (where n is the length of the left-side list?). What advantages does dropping the tail pointer have? 回答1: F#, like many other functional[-ish] languages, has

How to keep the stacktrace when rethrowing an exception out of catch-context?

谁说胖子不能爱 提交于 2019-12-08 15:59:29
问题 TL;DR: how to raise a previously caught exception later on, while preserving the original exception's stacktrace. Since I think this is useful with the Result monad or computation expression, esp. since that pattern is often used for wrapping an exception without throwing it, here's a worked out example of that: type Result<'TResult, 'TError> = | Success of 'TResult | Fail of 'TError module Result = let bind f = function | Success v -> f v | Fail e -> Fail e let create v = Success v let

Defining Modules VS.NET vs F# Interactive

Deadly 提交于 2019-12-08 15:59:23
问题 I have written this code which compiles and works perfectly in VS.NET 2010 module ConfigHandler open System open System.Xml open System.Configuration let GetConnectionString (key : string) = ConfigurationManager.ConnectionStrings.Item(key).ConnectionString however when I do a control + A and Alt + Enter to send this to FSI I get an error ConfigHandler.fs(2,1): error FS0010: Unexpected start of structured construct in definition. Expected '=' or other token. OK. So I change my code to module

F# / .NET null instance oddity

拜拜、爱过 提交于 2019-12-08 15:58:22
问题 I have this C# DLL: namespace TestCSProject { public class TestClass { public static TestClass Instance = null; public int Add(int a, int b) { if (this == null) Console.WriteLine("this is null"); return a + b; } } } And this F# app which references the DLL: open TestCSProject printfn "%d" (TestClass.Instance.Add(10,20)) No-one initiates the Instance static variable. Guess what the output of the F# app is? this is null 30 Press any key to continue . . . After a few tests I found out that

Do recursive sequences leak memory?

荒凉一梦 提交于 2019-12-08 15:51:54
问题 I like to define sequences recursively as follows: let rec startFrom x = seq { yield x; yield! startFrom (x + 1) } I'm not sure if recursive sequences like this should be used in practice. The yield! appears to be tail recursive, but I'm not 100% sure since its being called from inside another IEnumerable. From my point of view, the code creates an instance of IEnumerable on each call without closing it, which would actually make this function leak memory as well. Will this function leak