f#

xbuild and F# (vs2010) project

試著忘記壹切 提交于 2019-12-07 11:27:26
问题 I have a VS 2010 mixed-language solution that's primarily C#, but contains a windows service written in F#. I've had this building with xbuild in the in a parallel environment, but since upgrading to the packaged version of mono 2.10.5 from badgerports I've been unable to get it working. The error I typically encounter is: /home/alex/git/Solution/FSProject/FSProject.fsproj: error : Target named 'Build' not found in the project. What puzzles me is that looking at the project file, it doesn't

F# Change element in list and return full new list

岁酱吖の 提交于 2019-12-07 10:20:44
问题 I have a list of type (string * (int * int)) list . I want to be able to search through the list, finding the right element by it's string identifier, do a calculation on one of the ints , and then return the full, modified list. Example: Given a list let st = [("a1",(100,10)); ("a2",(50,20)); ("a3",(25,40))] I'm trying to make a function which gets one of the elements and subtracts number from one of the ints in the tuple. get ("a2",10) st //Expected result: st' = [("a1",(100,10)); ("a2",(40

Load F# assembly in Powershell and create a record expression

*爱你&永不变心* 提交于 2019-12-07 09:40:07
问题 I have a Powershell script. I successfully loaded a C# assembly and used a method contained in one the classes in that assembly: [MyCSharpAssembly.MyClass]::MyAssemblyMethod() . However the same did not work for F# . Is it at all possible? I have an assembly called Data.dll and it has a module called People.fs and People.fs defines record types: module People = type Teacher = { FirstName:string, LastName:string, Age:int } I want to load the Data.dll assembly to my Powershell script and then

Calling C# functions from F#

ⅰ亾dé卋堺 提交于 2019-12-07 09:30:39
问题 I was trying to call this function from f# http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.cloudstorageaccount.setconfigurationsettingpublisher.aspx The function signature is: CloudStorageAccount.SetConfigurationSettingPublisher (Action<string, Func<string, bool>>) : unit The C# call goes something like this: CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSettingPublisher) => { string configValue = "something" configSettingPublisher(configValue); });

How to create record class with default constructor

孤街浪徒 提交于 2019-12-07 09:01:32
问题 structures got default constructors like if I do type tagONEDEV_FlowRec = struct ....... end I can do new DeviceModel.tagONEDEV_FlowRec() but it doesn't work with this : let (<++|) device bytes size = let unmanagedPtr = Marshal.AllocHGlobal(size : int) Marshal.Copy( (bytes : byte array), 0, unmanagedPtr, size) Marshal.PtrToStructure(unmanagedPtr, (device : obj)) // Here Marshal.FreeHGlobal(unmanagedPtr) I need a record class here alike [<type:StructLayout(LayoutKind.Sequential, Pack=1,

Why can't F# infer the type in this case?

旧城冷巷雨未停 提交于 2019-12-07 08:51:09
问题 Consider the following sample code where I have a generic type and 2 static member constructors that create a specialized instance of the said type. type Cell<'T> = { slot: 'T } with static member CreateInt x : IntCell = { slot = x } static member CreateString x : StringCell = { slot = x} and IntCell = Cell<int> and StringCell = Cell<string> // Warnings on the next 2 lines let x = Cell.CreateInt 123 let y = Cell.CreateString "testing" I think I have the necessary type annotations in place and

Implementing C# method returning Task<T> in F#

Deadly 提交于 2019-12-07 08:41:21
问题 I'm creating a type in F# that inherits from a C# class that exposes a method that returns Task<T> in C#. I'm trying to work out what'd be the best way to do that in F# Say my C# looks like this: public class Foo { public TextWriter Out { get { return Console.Out; } } public virtual Task<SomeEnum> DoStuff() { return Task.FromResult(SomeEnum.Foo); } } public enum SomeEnum { Foo, Bar } My first pass of inheriting that type in F# looks like so: type Bar() = inherits Foo() override this.DoStuff()

Merge/join seq of seqs

情到浓时终转凉″ 提交于 2019-12-07 08:38:50
问题 Slowly getting the hang of List matching and tail recursion, I needed a function which 'stitches' a list of lists together leaving off intermediate values (easier to show than explain): merge [[1;2;3];[3;4;5];[5;6;7]] //-> [1;2;3;4;5;6;7] The code for the List.merge function looks like this: ///Like concat, but removes first value of each inner list except the first one let merge lst = let rec loop acc lst = match lst with | [] -> acc | h::t -> match acc with | [] -> loop (acc @ h) t | _ ->

How can I use WPF menus and dialog boxes in F#?

﹥>﹥吖頭↗ 提交于 2019-12-07 08:38:37
问题 I've been trying to find an example of using XAML and F# - without C# - to set up traditional menus and dialog boxes. Everything I can find online either uses C# or it is old, before the most recent versions of F# and .NET. Can anyone suggest an example I can look at? Thanks. 回答1: When you try to learn WPF, you come across many C# examples based on "good old" code behind rather than MVVM or MVC. The following explains how to quickly create an F# WPF code behind application. Using this, it

F# type providers with Portable Library

こ雲淡風輕ζ 提交于 2019-12-07 08:27:28
问题 I'm building a Windows 8 application and am finding myself wanting to include a list of ISO-4217 codes, which I have in up-to-date form in XML. Naturally, there are a couple of these codes for all countries. I figured a Type Provider would be an excellent fit. However, since they emit code, I can't use them with Portable Libraries. How do I compile the type provider so that it doesn't use emit, in order to use the XML I've got? 回答1: I don't have experience with creating a Type Provider that