c#-to-f#

Reading cell contents in an Excel file with F# and Open XML SDK

天涯浪子 提交于 2021-02-10 13:16:55
问题 I can't compile the following code, which has been translated from C#. The compiler produced this error: error FS0010: Incomplete structured construct at or before this point in implementation file. Expected incomplete structured construct at or before this point or other token. // Assemblies open System open System.Linq open System.Data open System.Windows open DocumentFormat.OpenXml // Also install DocumentFormat.OpenXml from nuget open DocumentFormat.OpenXml.Packaging open DocumentFormat

Reading cell contents in an Excel file with F# and Open XML SDK

╄→尐↘猪︶ㄣ 提交于 2021-02-10 13:16:00
问题 I can't compile the following code, which has been translated from C#. The compiler produced this error: error FS0010: Incomplete structured construct at or before this point in implementation file. Expected incomplete structured construct at or before this point or other token. // Assemblies open System open System.Linq open System.Data open System.Windows open DocumentFormat.OpenXml // Also install DocumentFormat.OpenXml from nuget open DocumentFormat.OpenXml.Packaging open DocumentFormat

System.Linq.Enumerable.OfType<T> - is there a F# way?

送分小仙女□ 提交于 2021-02-08 05:39:15
问题 I'm looking to use the F# WSDL Type Provider. To call the web service I am using, I need to attach my client credentials to the System.ServiceModel.Description.ClientCredentials . This is the C# code I have: var serviceClient = new InvestmentServiceV1Client.InvestmentServiceV1Client(); foreach (ClientCredentials behaviour in serviceClient.Endpoint.Behaviors.OfType<ClientCredentials>()) { (behaviour).UserName.UserName = USERNAME; (behaviour).UserName.Password = PASSWORD; break; } This is the F

Error F# - c# async calls : converting Threading.Tasks.Task<MyType> to Async<'a>

这一生的挚爱 提交于 2020-02-24 05:06:09
问题 When I try to call an async method that is in C# library from my F# code. I get the following compilation error. This expression was expected to have type Async<'a> but here has type Threading.Thread.Tasks.Task SendMessageAsync is in C# library and returns Threading.Thread.Tasks.Task<MyType> let sendEmailAsync message = async { let! response = client.SendMessageAsync(message) return response } 回答1: For converting between Task<'T> and Async<'T> there is a built-in Async.AwaitTask function. To

The F# equivalent of C#'s 'out'

一世执手 提交于 2020-01-22 13:49:12
问题 I am rewriting a C# library to F# and I need to translate the following code bool success; instance.GetValue(0x10, out success); what is the equivalent of the out keyword in F#? 回答1: Neither wasatz's answer nor Max Malook's is complete. There are three ways of calling methods with out parameters. The second and third ways also work with ref parameters. For the examples, assume the following type: open System.Runtime.InteropServices //for OutAttribute type SomeType() = member this.GetValue

Simple XNA 2D demo: why is my F# version slower than C# version?

血红的双手。 提交于 2020-01-13 04:48:11
问题 When running this XNA application it should display a rotated rectangle that moves from top-left corner to bottom-right corner. It looks like my F# version is noticeably much slower. It seems that the Draw method skips a lot of frames. I am using VS 2012 RC, XNA 4.0, .NET 4.5, F# 3.0. I am trying to make it as functional as possible. What could be the reason for poor performance? C#: class Program { static void Main(string[] args) { using (var game = new FlockGame()) { game.Run(); } } }

Convert C# code to F# code: lists manipulation

两盒软妹~` 提交于 2020-01-06 04:52:04
问题 Good morning at all, first I present myself: my name is Mattia and I'm a student in Computer Science. I've a problem with three function that I've already implement in two other programming language (C# and Python), using imperative loop like for and while, but what I've to do is to convert them in the recursive style. The function in C# are: resetList: given two list, the method initialize the counters inside the object of first list, and put the new object in the second list. public static

Accessing dynamic property in F#

与世无争的帅哥 提交于 2020-01-03 18:45:27
问题 I was trying to access dynamic property in Nancy. In Nancy if pass parameter in query it comes as dynamic property. How can I access that. There are many discussion / question about this but every where, first it is of creating dynamic and then consuming it. How can I consume what is already created? Here are two code snippet public class ParameterModule : NancyModule { public ParameterModule():base("/{about}") { this.Get["/"] = (parameters) => "Hello About" + parameters.about; } } and for F#

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