f#

Visual Studio F# project: Can't have two folders in a file tree with the same name?

江枫思渺然 提交于 2020-01-13 07:48:50
问题 In Visual Studio 2013, one of my projects includes: <ItemGroup> <Compile Include="Entity\Abstract\Entity.fs" /> <Compile Include="Entity\HumanEntity.fs" /> <Compile Include="State\Abstract\State.fs" /> <Compile Include="State\Abstract\HumanState.fs" /> <Compile Include="State\Human\HumanIdleState.fs" /> <Compile Include="State\Human\HumanAwakenState.fs" /> </ItemGroup> Visual Studio chokes on this, claiming that: The project 'Entity.fsproj' could not be opened because opening it would cause a

How do I add a reference to F# Portable Library from C# Portable Class Library (PCL)

﹥>﹥吖頭↗ 提交于 2020-01-13 07:36:27
问题 I have a project which contains two F# projects and a C# project in which I'd like to write some XUnit tests: FS_PL: F# 3.1 (3.3.1.0) Portable Library FS_PL_Legacy: F# 31. (2.3.5.1) Portable Library (Legacy) Tests: C# .NET 4.5/Win8 C# Portable Class Library (PCL) I am unable to add a reference from Tests to either of the F# libraries. When I try to add a reference to FS_PL, I am presented with a dialog that states "Unable to add a reference to project 'FS_PL'. The targets of Portable Library

F# Equivalent to Enumerable.OfType<'a>

允我心安 提交于 2020-01-13 07:34:05
问题 ...or, how do I filter a sequence of classes by the interfaces they implement? Let's say I have a sequence of objects that inherit from Foo, a seq<#Foo> . In other words, my sequence will contain one or more of four different subclasses of Foo. Each subclass implements a different independent interface that shares nothing with the interfaces implemented by the other subclasses. Now I need to filter this sequence down to only the items that implement a particular interface. The C# version is

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(); } } }

How to implicitly convert to common super types in F# pattern matches?

独自空忆成欢 提交于 2020-01-12 17:39:10
问题 Problem Summary At the moment when using f# I must explicitly coerce a value to the parent type of its type in order to get pattern matching expressions to type check correctly. I would ideally like a neater way of doing. Example Suppose I have some class hierachy: type Foo () = abstract member Value : unit -> string type A (i:int) = inherit Foo () override this.Value () = i.ToString() type B (s:string) = inherit Foo () override this.Value () = s Ideally, and in some programming languages in

Generics with interfaces in F#

主宰稳场 提交于 2020-01-12 15:14:25
问题 In C# one can state that a generic parameter must implement a certain interface like so: public class Something<T> where T : IComparable { ... } How does one specify this in F#? 回答1: Generic constraints use "when" in F#: type Foo<'a when 'a :> IComparable> = member x.Bla = 0 来源: https://stackoverflow.com/questions/770143/generics-with-interfaces-in-f

Generics with interfaces in F#

那年仲夏 提交于 2020-01-12 15:14:12
问题 In C# one can state that a generic parameter must implement a certain interface like so: public class Something<T> where T : IComparable { ... } How does one specify this in F#? 回答1: Generic constraints use "when" in F#: type Foo<'a when 'a :> IComparable> = member x.Bla = 0 来源: https://stackoverflow.com/questions/770143/generics-with-interfaces-in-f

How do you curry the 2nd (or 3rd, 4th, …) parameter in F# or any functional language?

房东的猫 提交于 2020-01-12 13:47:36
问题 I'm just starting up with F# and see how you can use currying to pre-load the 1st parameter to a function. But how would one do it with the 2nd, 3rd, or whatever other parameter? Would named parameters to make this easier? Are there any other functional languages that have named parameters or some other way to make currying indifferent to parameter-order? 回答1: Typically you just use a lambda: fun x y z -> f x y 42 is a function like 'f' but with the third parameter bound to 42. You can also

Typed FP: Tuple Arguments and Curriable Arguments

我的未来我决定 提交于 2020-01-12 07:35:10
问题 In statically typed functional programming languages, like Standard ML, F#, OCaml and Haskell, a function will usually be written with the parameters separated from each other and from the function name simply by whitespace: let add a b = a + b The type here being " int -> (int -> int) ", i.e. a function that takes an int and returns a function which its turn takes and int and which finally returns an int. Thus currying becomes possible. It's also possible to define a similar function that

How does pattern matching work behind the scenes in F#?

∥☆過路亽.° 提交于 2020-01-12 06:41:22
问题 I am completely new to F# (and functional programming in general) but I see pattern matching used everywhere in sample code. I am wondering for example how pattern matching actually works? For example, I imagine it working the same as a for loop in other languages and checking for matches on each item in a collection. This is probably far from correct, how does it actually work behind the scenes? 回答1: It depends on what kind of pattern matching do you mean - it is quite powerful construct and