f#

How to update a table in database using LINQ in F#?

血红的双手。 提交于 2019-12-13 15:22:16
问题 I have seen plenty of examples on how to query the database but nothing on how to update records. Below is the simple code that I wrote to retrieve a table, but can someone explain me how can I modify a field, say lastActiveDate, and update the table on the database Thank you, suday open System open Microsoft.FSharp.Linq let connString = "Server=localhost;Database=myDb;Trusted_Connection=True;" let db = new MyDb(connString) db.Log <- System.Console.Out let res = Query.query <@ seq { for users

static resolved type parameters expects additional expression

浪子不回头ぞ 提交于 2019-12-13 15:21:58
问题 The following code let inline foo< ^T, ^U when ^T : (member foo : (^U -> ^T) -> ^T -> ^T)> (f:(^U -> ^T)) (t:^T) : ^T = (^T : (member foo : (^U -> ^T) -> ^T -> ^T) f,t ) yields this error let inline foo< ^T, ^U when ^T : (member foo : (^U -> ^T) -> ^T -> ^T)> (f:^U) (t:^T) : ^T = (^T : (member foo : (^U -> ^T) -> ^T -> ^T) f,t );; -----------------------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ /stdin(45,96):

F# printfn anomaly

懵懂的女人 提交于 2019-12-13 15:15:11
问题 Can anyone please explain why this results in an error: let xs = [| "Mary"; "Mungo"; "Midge" |] Array.iter printfn xs Whilst this does not: Array.iter printfn [| "Mary"; "Mungo"; "Midge" |] 回答1: The signature of printfn is Printf.TextWriterFormat<'a> -> 'a . The compiler infers literal values of strings as Printf.TextWriterFormat<unit> but cannot do so with dynamic strings. You can help the compiler in the first example by adding correct type annotation: let xs: Printf.TextWriterFormat<unit>

#load a package in F# interactive (FSharpChart.fsx)

♀尐吖头ヾ 提交于 2019-12-13 14:28:49
问题 Hi i'm a noob and asking this newbie question, please forgive me. I've installed successfully FSharpChart in my local directory ... Added package 'MSDN.FSharpChart.dll.0.60.0' to folder 'C:\Users\Fagui\Documents\GitHub\Learning Fsharp\Expert in F\packages' Added package 'MSDN.FSharpChart.dll.0.60.0' to 'packages.config' Successfully installed 'MSDN.FSharpChart.dll 0.60.0' to Expert in F now, if i do #load "FSharpChart.fsx";; ^^^^^^^^^^^^^^^^^^^^^^^ stdin(4,1): error FS0078: Unable to find the

C# types for empty F# discriminated union cases

删除回忆录丶 提交于 2019-12-13 14:27:11
问题 I'm accessing an F# discriminated union using C# and trying to use a switch statement over the union's cases. This works fine for values that have at least one field but not for empty values as these don't have a corresponding class generated, only a property. Consider the following F# discriminated union. type Letter = A of value:int | B of value:string | C | D In C# I have the following switch statement inside a function that has an argument letter of type Letter: switch (letter) { case A a

F# generating types in a type extension function within a type provider

笑着哭i 提交于 2019-12-13 14:23:28
问题 I have the following problem: Within my type provider, I need to extend a generic type, that I have previously defined, with a method that will return an instance of this generic type. What I mean is, let's say we have : type receiveType<'a> = class val Next:int val Type:string new (state,stateType) = {Next = state;Type = stateType;} end later within my typeprovider I want to extend the type with the following function: [<TypeProvider>] type ProviderTest() as this= ( inherit

The type 'XmlProvider' is not defined

≯℡__Kan透↙ 提交于 2019-12-13 14:07:21
问题 I'm trying to use the FSharp.Data third party library but am getting an error The type 'XmlProvider' is not defined on the XmlProvider class. namespace KMyMoney open FSharp.Data module Read = let xml = File.ReadAllText("KMyMoneySampleFile.xml") type KMyMoneySource = XmlProvider<xml> I'm using NuGet to get the library. Library is 'FSharp.Data 1.1.8' When I type FSharp.Data. There are four options given: Csv , FreebaseOperators , Json , and RuntimeImplementation . Am I missing something? I'm

Embedding F# Interactive throw System.Exception: 'Error creating evaluation session: StopProcessingExn None'

梦想的初衷 提交于 2019-12-13 13:48:59
问题 I'm working through the Embedding F# Interactive example from here but like this post, I'm having an issue with the following line throwing an exception: let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream) The exception thrown is: "System.Exception: 'Error creating evaluation session: StopProcessingExn None'" My project is being run from VS2017 Enterprise, setup as a simple F# console app, with the Target Framework as .NET Core 2.0 . The version of

Calling C# function with multiple arguments from F#

久未见 提交于 2019-12-13 13:29:54
问题 It is easy to call f:Func<'T, 'T> from F# as 'T -> 'T by using f.Invoke But how should I call f:Func<'T, 'T, 'T> from F# as 'T -> 'T -> 'T ? When I use f.Invoke I get 'T * 'T -> 'T , i.e. a tuple instead of two arguments. 回答1: Try: let g = f.Invoke |> FuncConvert.FuncFromTupled 回答2: Note that you do not need to turn the function into a function taking two arguments if you just want to call it. If you already know the arguments for the function, then you can just call it as a function taking a

Incomplete pattern match when two patterns share a `when` clause

寵の児 提交于 2019-12-13 13:25:49
问题 A common surprise for beginning F# programmers is the fact that the following is an incomplete match: let x, y = 5, 10 match something with | _ when x < y -> "Less than" | _ when x = y -> "Equal" | _ when x > y -> "Greater than" But I just encountered a situation that surprised me. Here's a small bit of sample code to demonstrate it: type Tree = | Leaf of int | Branch of Tree list let sapling = Branch [Leaf 1] // Small tree with one leaf let twoLeafTree = Branch [Leaf 1; Leaf 2] let describe