f#

F# attributes, typeof, and “This is not a constant expression”

北慕城南 提交于 2019-12-13 13:13:03
问题 EDIT: Added a more complete example, which clarified the problem. Some .NET attributes require a parameter of type Type . How does one declare these parameters in F#? For example, in C# we can do this: [XmlInclude(typeof(Car))] [XmlInclude(typeof(Truck))] class Vehicle { } class Car : Vehicle { } class Truck : Vehicle { } But, in F# the following... [<XmlInclude(typeof<Car>)>] [<XmlInclude(typeof<Truck>)>] type Vehicle() = class end type Car() = inherit Vehicle() type Truck() = inherit Car()

How to do pointfree style with long parameter list

烂漫一生 提交于 2019-12-13 13:02:55
问题 I've got a function that creates an Async workflow, and the function that takes 10 arguments in curry style. e.g. let createSequenceCore a b c d e f g h i j = async { ... } I want to create another function to start that workflow, so I've got let startSequenceCore a b c d e f g h i j = Async.StartImmediate (createSequenceCore a b c d e f g h i j) Is there any way I can get rid of those redundant parameters? I tried the << operator, but that only lets me remove one. let startSequenceCore a b c

F# break from while loop

流过昼夜 提交于 2019-12-13 11:52:43
问题 There is any way to do it like C/C# ? For example (C# style) for( int i=0; i<100; i++) { if(i==66) break; } 回答1: The short answer is no. You would generally use some higher-order function to express the same functionality. There is a number of functions that let you do this, corresponding to different patterns (so if you describe what exactly you need, someone might give you a better answer). For example, tryFind function returns the first value from a sequence for which a given predicate

Passing through console output from Process.Start directly

安稳与你 提交于 2019-12-13 09:27:34
问题 I'm using Process.Start from a .NET command-line application to run another command-line application. I don't want to capture the output of the application, I just want it to go to the console directly. With the program below the output seems to just disappear into thin air. If I leave CreateNoWindow at the default false then I do get the output in a fresh console window, but I want it in the original console window. UseShellExecute <- false is also needed otherwise CreateNoWindow is forced

Getting started with basic transportation problems like Wolf, Cabbage, Goat with either C# or F# [closed]

混江龙づ霸主 提交于 2019-12-13 09:12:44
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . OK. this might be a very basic question to please don't flame me but I have been googling I want to learn how to write solutions to

Mutable Vector field is not updating in F#

删除回忆录丶 提交于 2019-12-13 07:37:19
问题 let gradientDescent (X : Matrix<double>) (y :Vector<double>) (theta : Vector<double>) alpha (num_iters : int) = let J_history = Vector<double>.Build.Dense(num_iters) let m = y.Count |> double theta.At(0, 0.0) let x = (X.Column(0).PointwiseMultiply(X*theta-y)) |> Vector.sum for i in 0 .. (num_iters-1) do let next_theta0 = theta.[0] - (alpha / m) * ((X.Column(0).PointwiseMultiply(X*theta-y)) |> Vector.sum) let next_theta1 = theta.[1] - (alpha / m) * ((X.Column(1).PointwiseMultiply(X*theta-y)) |

How to use FSharpx TaskBuilder with functions taking parameters

假装没事ソ 提交于 2019-12-13 07:14:27
问题 I have been lately programming with the FSharpx library and especially its TaskBuilder. Now I wonder if it should be possible to define a function which takes parameters and takes a result. Such as let doTask(parameter:int) = let task = TaskBuilder(scheduler = TaskScheduler.Current) task { return! Task.Factory.StartNew(fun() -> parameter + 1) } match FSharpx.Task.run doTask(1) with | _ -> () Looking at the source code I see run expects a function taking no parameters and returning a Task<'a>

Wrapping a function with an indeterminate number of parameters in F#

情到浓时终转凉″ 提交于 2019-12-13 06:23:03
问题 I'm trying to write a simple wrapper class in F# that takes a function that returns a string, and returns a function that takes the same parameters and returns the string from the input 'wrapped'. The following code works for functions that take a single variable (so test works fine): open System let myFunc anotherFunc = fun x -> "boo" + anotherFunc x + "unboo" let Func2 toDouble = (toDouble * 2).ToString () let test = myFunc Func2 let Func3 numOne numTwo = (numOne * numTwo).ToString () let

How to include a stored procedure in F#

ⅰ亾dé卋堺 提交于 2019-12-13 06:21:57
问题 In the following code, I would like to insert or update rows in an SQL table through F#. It takes a matrix of tuple representing users and an associated scores (usrID,score) which are the results of some F# calculations. Now I want to update a SQL table called UserScoresTable. The code I wrote is working but is very slow. let cnn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings.Item("Database").ConnectionString) cnn.Open() // Definition d'une fonction qui

F# and C# Web Service cannot open namespace

梦想与她 提交于 2019-12-13 06:03:06
问题 I want to use the VS2012 F# and C# Web Service template by Daniel Mohl. However, I run into a frustrating issue of not being able to use the generated code in a script file: namespace FSharpWcfServiceApplicationTemplate open System open FSharpWcfServiceApplicationTemplate.Contracts type Service1() = interface IService1 with member x.GetData value = sprintf "%A" value member x.GetDataUsingDataContract composite = match composite.BoolValue with | true -> composite.StringValue <- sprintf "%A%A"