f#

Why do I get a missing method exception runtime when creating a SqlClient type?

谁说胖子不能爱 提交于 2020-01-03 17:04:34
问题 I have the following code: open FSharp.Data [<Literal>] let connectionString = @"Data Source=(local)\SQLExpress;Integrated Security=SSPI;Database=SfagStage" type InsertEnhet = SqlCommandProvider<"Sql\InsertEnhet.sql", connectionString> let insertEnhet (enhet:Enhet) = let cmd = new InsertEnhet() // <<--- This generates an error runtime cmd.Execute(enhet.Navn, enhet.Enhetsnummer, enhet.LEIKode, enhet.Kommune, DateTime.Now) The row where I create the command is what causing the missing method I

F# active pattern as non-static member

半世苍凉 提交于 2020-01-03 16:49:43
问题 I'm not sure if non-static public member active patterns are allowed but you can define them without the compiler complaining. If they are allowed what's the syntax for matching against one? The compiler is giving me a type mismatch for Foo in FooBar2.doSomething. Expecting a 'a -> Choice<'b,'c> given 'a -> 'd -> Choice<unit,unit> // No error in this class, static works great type FooBar() = static member (|Foo|Bar|) (x, y) = match x = y with | true -> Foo | false -> Bar member x.doSomething

Why isn't F# able to resolve overload between Async<> and Async<Result<>>?

自作多情 提交于 2020-01-03 16:44:40
问题 I want to understand the F# overload resolution a little better in a specific context. I'm writing a simple asyncResult workflow/computation expression to make error handling in the style of railway-oriented programming easier to use when combined with async workflows. I do this by overloading the Bind method on the workflow builder. This is fairly standard and used in all guides I've seen (and is also used in e.g. Chessie/ErrorHandling.fs). I have one overload that accepts an Async<_> and

Why isn't F# able to resolve overload between Async<> and Async<Result<>>?

房东的猫 提交于 2020-01-03 16:44:14
问题 I want to understand the F# overload resolution a little better in a specific context. I'm writing a simple asyncResult workflow/computation expression to make error handling in the style of railway-oriented programming easier to use when combined with async workflows. I do this by overloading the Bind method on the workflow builder. This is fairly standard and used in all guides I've seen (and is also used in e.g. Chessie/ErrorHandling.fs). I have one overload that accepts an Async<_> and

Sometimes F# doesn't inline functions even if it is marked `inline`?

孤人 提交于 2020-01-03 16:36:46
问题 let inline funA x = printf "A" x > 3 let inline funB myFun x = printf "B" myFun x let foo () = funB funA 7 IL for foo .method public static bool foo () cil managed { // Method begins at RVA 0x2278 // Code size 31 (0x1f) .maxstack 4 .locals init ( [0] class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4<class [FSharp.Core]Microsoft.FSharp.Core.Unit, class [mscorlib]System.IO.TextWriter, class [FSharp.Core]Microsoft.FSharp.Core.Unit, class [FSharp.Core]Microsoft.FSharp.Core.Unit> ) IL_0000:

How to convert C# code that uses Shell COM to F#?

蹲街弑〆低调 提交于 2020-01-03 13:56:11
问题 I have the following C# method: private static bool IsLink(string shortcutFilename) { var pathOnly = Path.GetDirectoryName(shortcutFilename); var filenameOnly = Path.GetFileName(shortcutFilename); var shell = new Shell32.Shell(); var folder = shell.NameSpace(pathOnly); var folderItem = folder.ParseName(filenameOnly); return folderItem != null && folderItem.IsLink; } I have tried converting this to F# as: let private isLink filename = let pathOnly = Path.GetDirectoryName(filename) let

What/where is get_Zero in F#'s int?

血红的双手。 提交于 2020-01-03 13:38:55
问题 I'm just learning F#, and while playing at tryfsharp.org I noticed that if I change this code: [0..100] |> List.sum to ["A"; "B"; "D"] |> List.sum I get the following error: The type 'string' does not support the operator 'get_Zero' (Here's the script that you can run/amend in your browser, though it only seems to work in IE for me!) When I checked the definition of List.sum; it says that the type must have a static member called Zero. This seems to explain the error; except for the fact that

How do I find a substring within a string in F#?

那年仲夏 提交于 2020-01-03 13:31:06
问题 I found a "fun" project online for f# and the idea behind it is to find the number of substrings within a given string. Here's the prompt: Description: You are given a DNA sequence: a string that contains only characters 'A', 'C', 'G', and 'T'. Your task is to calculate the number of substrings of sequence, in which each of the symbols appears the same number of times. Example 1: For sequence = "ACGTACGT", the output should be 6 All substrings of length 4 contain each symbol exactly once (+5)

Optimizing syntax for mapped async sequences in F#

耗尽温柔 提交于 2020-01-03 13:30:03
问题 I am trying to figure out efficient syntax for the following F# expression. Let's say I have an F# async computation: let asyncComp n = async { return n } It has a signature 'a -> Async<'a> . Now I define a sequence of those: let seqOfAsyncComps = seq { yield asyncComp 1 yield asyncComp 2 yield asyncComp 3 } Now I have an item of seq<Async<int>> . What if I want to asynchronously map the elements from seq<Async<int>> to seq<Async<int>> . This won't work: let seqOfAsyncSquares =

.NET DateTime to time_t in seconds

非 Y 不嫁゛ 提交于 2020-01-03 11:58:23
问题 There is C code : time1=((double)dt1-25569.0)*86400.0; it's convert from TDateTime (VCL) to time_t format in seconds, so finally I need to get time_t format from .NET DateTime about time_t : It is almost universally expected to be an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC. This is due to historical reasons, since it corresponds to a unix timestamp, but is widely implemented in C libraries across all platforms. So to get seconds in .NET I'm