f#

FSharpChart.SaveAs () saves blank image if called before chart rendering is complete

强颜欢笑 提交于 2020-01-14 08:44:11
问题 When run in F# Interactive, I expect the following code to create a simple pie chart and save it to disk: let pie = FSharpChart.Pie([("Apples",1);("Oranges",2);("Bananas",3)]) FSharpChart.SaveAs "test.png" ChartImageFormat.Png pie However, what actually gets saved in "test.png" is a blank image. The same happens if I pipe the chart into the FShartChart.SaveAs function. But if I first execute only the chart creation code and give the chart time to render before manually executing SaveAs, the

Are float array, float[], and double[] different, or the same?

。_饼干妹妹 提交于 2020-01-14 08:22:28
问题 I'm writing my code as if these are all the same thing, and having no problems, but it's starting to confuse me when I hover over a function in Visual Studio and see that the type definitions contain 3 different types that I had thought were all the same. Are they the same? Or are they different? 回答1: They are the same. See the type abbreviations at the bottom of the FSharp.Core documentation. float = double = System.Double and array<'T> = 'T[] . You can also define your own type

Can existing types be extended to work with Seq.sum, etc?

南楼画角 提交于 2020-01-14 08:04:30
问题 Been working with a lot of TimeSpans recently, and have a need to get sums & averages. However, TimeSpan defines neither operator get_Zero nor DivideByInt, so Seq.sum and Seq.average can't be used directly with this type. The following fails to compile: open System type System.TimeSpan with static member Zero with get() = TimeSpan() static member (/) (n:DateTime, d:int) = DateTime( n.Ticks / (int64) d ) let ts = [ TimeSpan(10L); TimeSpan(99L) ] let sum = ts |> Seq.sum let avg = ts |> Seq

Can existing types be extended to work with Seq.sum, etc?

纵然是瞬间 提交于 2020-01-14 08:04:26
问题 Been working with a lot of TimeSpans recently, and have a need to get sums & averages. However, TimeSpan defines neither operator get_Zero nor DivideByInt, so Seq.sum and Seq.average can't be used directly with this type. The following fails to compile: open System type System.TimeSpan with static member Zero with get() = TimeSpan() static member (/) (n:DateTime, d:int) = DateTime( n.Ticks / (int64) d ) let ts = [ TimeSpan(10L); TimeSpan(99L) ] let sum = ts |> Seq.sum let avg = ts |> Seq

F# XML multiline documentation, Visual Studio 2017

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-14 07:56:14
问题 I would like to add a multi-line XML documentation that will appear in the Intelli-Sense bubble when my mouse hover over it. See for example: When I am using Visual Studio 2015, the following code works (see screenshots below), but now when I use Visual Studio 2017, it does not work anymore: See the following screenshot taken in VS2015 and VS2017 VS2015: VS2017: After searching stackoverflow and other website, I tried some codes, but it is still not working. // My failed guesses /// This also

F# FTP Fails where C# Succeeds

我怕爱的太早我们不能终老 提交于 2020-01-14 04:54:06
问题 I've an application written in C# (.Net 3.5) with this code. using System; using System.Net; string strURI = String.Format("ftp://x{0}ftp/%2F'{1}'", parm1, parm2); FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(strURI); ftp.Proxy = null; ftp.KeepAlive = true; ftp.UsePassive = false; ftp.UseBinary = false; ftp.Credentials = new NetworkCredential("uid", "pass"); ftp.Method = WebRequestMethods.Ftp.DownloadFile; FtpWebResponse response = (FtpWebResponse)ftp.GetResponse(); ... I've

Creating a logging function from Logary/Noop.fs in F#

随声附和 提交于 2020-01-14 04:35:11
问题 I am editing the Noop.fs file from logary/Noop.fs. I am currently trying to add two functions. That is the one to create the Event Sourcing connection (I understand I should ideally move it somewhere else, so that it is not created every time I want to log something, but it should rather exist on a global level, where should I add it then?). The second function is to send the log as an event to the EventStore stream . I have created the function, but I need to call it. Where do I call it? I

Parametric Polymorphism vs Subtype polymorphism F#

风格不统一 提交于 2020-01-14 01:44:43
问题 What is the difference (if any) between these two F# type signatures? UseTheStream<'a when 'a :> Stream> : 'a -> unit and UseTheStream : (stream : Stream) -> unit Do they mean the same thing in this case? msdn says the following about the (:>) Type Constraint type-parameter :> type -- The provided type must be equal to or derived from the type specified, or, if the type is an interface, the provided type must implement the interface. This would indicate that the two signatures are saying the

Drag and Drop in Silverlight with F# and Asynchronous Workflows

只谈情不闲聊 提交于 2020-01-13 18:58:57
问题 I'm trying to implement drag and drop in Silverlight using F# and asynchronous workflows. I'm simply trying to drag around a rectangle on the canvas, using two loops for the the two states (waiting and dragging), an idea I got from Tomas Petricek's book "Real-world Functional Programming", but I ran into a problem: Unlike WPF or WinForms, Silverlight's MouseEventArgs do not carry information about the button state, so I can't return from the drag-loop by checking if the left mouse button is

what is use cases of F# explicit type parameters?

╄→гoц情女王★ 提交于 2020-01-13 16:57:55
问题 As I know, explicit type parameters in value definitions is a one way to overcome "value restriction" problem. Is there another cases when I need to use them? Upd : I mean "explicitly generic constructs", where type parameter is enclosed in angle brackets, i.e. let f<'T> x = x 回答1: This would likely be rare, but when you want to prevent further generalization (§14.6.7): Explicit type parameter definitions on value and member definitions can affect the process of type inference and