f#

Specified Visual is already a child of another Visual or the root of a CompositionTarget

﹥>﹥吖頭↗ 提交于 2019-12-10 13:43:06
问题 WPF Visualizer Visual Tree canvas canvas.Children.Add poly |> ignore Specified Visual is already a child of another Visual or the root of a CompositionTarget. Don't think it's 1), not sure what 2) is? Using Visual Studio 2010, F# 2.0, WPF, ... not XAML 回答1: It's a bit hard to diagnose the problem without a relevant code sample, but maybe the problem is that you tried to add the same polygon to the canvas' children twice. This is the code I burped up to reproduce your error: type SimpleWindow(

Adding F# to Visual Studio 2010 C# express - is it possible?

流过昼夜 提交于 2019-12-10 13:38:59
问题 My question relates to: will there be a F# express edition? Given there is no VS 2010 F# express - I would like to know what the latest wisdom is for installing F# onto VS 2010 C# express. Is it possible at all? Thanks. 回答1: Note that a release today enables F# inside the free VS2010 shell, offering an express-like F# experience. http://blogs.msdn.com/b/dsyme/archive/2010/08/17/announcing-the-f-2-0-free-tools-for-net-4-0.aspx 来源: https://stackoverflow.com/questions/3287157/adding-f-to-visual

obj[] and string[] as parameters

空扰寡人 提交于 2019-12-10 13:38:20
问题 I am using Microsoft.FSharp.Reflection.FSharpValue.MakeUnion and this requires a Reflection.UnionCaseInfo and an obj[] (that can be empty) as parameters. However, I am getting a Type mismatch. Expecting a obj [] but given a string [] The type 'obj' does not match the type 'string' when calling with the result of a function that is a string[] . The simplest example I can create of this happening is as follows (I have a test wrapped around this and it doesn't compile because of the line marked

Shared cases in F# discriminated unions

馋奶兔 提交于 2019-12-10 13:34:42
问题 I want to write something like this: type NumExp = Num of float type Exp = | Num of float | Dot of NumExp * NumExp | Op of string * Exp * Exp let getValue (Num(n) : NumExp) = n The compiler complains about a conflict between NumExp and Exp in getValue . Even the following fails: let getValue (nn : NumExp) = match nn with | Num(n) -> n Is there a way to use the same case in both discriminated unions that works with functions? The DU definitions themselves are OK. I want to use the same case to

Using MSTest with F#

孤人 提交于 2019-12-10 13:32:54
问题 Is it possible to use MSTest with F# in VS2010. People has asked this question many times. But I can't seem to find a solution among the answers. Has anybody been able to use MSTest for F# unit testing or should I stick to NUnit? 回答1: I think you should stick to NUnit. Have a look here: http://connect.microsoft.com/VisualStudio/feedback/details/564586/make-using-mstest-more-accessible-to-f-projects. There is no progress with that issue. 回答2: Yes, you can use MsTest with F# in VS2010. At the

Consume C# event from F#

耗尽温柔 提交于 2019-12-10 13:27:34
问题 Followed Functional Reactive Programming tutorial, where stream of events ( Observable ) is directly created from System.Timers.Timer.Elapsed event. let timer = new System.Timers.Timer(float 1) let observable = timer.Elapsed observable |> Observable.subscribe ... Have class defined in C# public delegate void OnMessageDelegate(Message message); public class Notifier : INotifier { public event OnMessageDelegate OnMessage; public void Notify(Message message) => OnMessage?.Invoke(message); }

F# forward pipe to convert from int to bigint

家住魔仙堡 提交于 2019-12-10 13:27:04
问题 I am fairly new to F# and came up across this scenario and was hoping someone could explain why my compiler doesnt like the code... If in F# I do the following... let FloatToInt = 10.0 |> int let IntToFloat = 10 |> float Everything is fine and the number is cast to the relevant data type... if however I do the following... let IntToBigInt = 10 |> bigint I get a error "Invalid use of type name or object constructor." I assume that this is because there isnt an operator overload for the forward

Pattern matching against generic type using 'flexible' type parameter

僤鯓⒐⒋嵵緔 提交于 2019-12-10 13:26:12
问题 match value with | :? list<#SomeType> as l -> l //Is it possible to match any list of a type derived from SomeType? | _ -> failwith "doesn't match" 回答1: No, it's unfortunately not possible to do something like this - the CLR doesn't provide any efficient way of doing that kind of type test. See How to cast an object to a list of generic type in F# and F# and pattern matching on generics in a non-generic method implementing an interface for a few (rather ugly) solutions. 回答2: As already

Finding local mins in an array

扶醉桌前 提交于 2019-12-10 13:23:29
问题 Is there a easy way to determine the local min and maxes of an array of values. For example Element Value Note 1 1 2 3 3 5 4 6 5 7 max 5 5 6 4 min 7 6 8 9 9 10 max 10 8 11 7 12 5 min 13 10 so an array that is defined like: let arr = [|1;3;5;6;7;5;4;6;9;10;8;7;5;10|] would identify mins = [|4;5|] and maxs = [|7;10|] It could be a list or Sequence as well as an array. Two questions Is there any faciliities in F# that that lend themselves to this task Is there a common algorithm for determining

Min/Max and most frequent element of a list

偶尔善良 提交于 2019-12-10 13:18:19
问题 I have to write a program which give in output a tuple with: min and max of a not-empty list and the value that appears most often. In particular: min_max [1;0;-1;2;0;-4] ==> (-4; 2) min_max: int list -> (int * int) mode [-1;2;1;2;5;-1;5;5;2] ==> 2 mode: int list -> int This is the code that I wrote for max (min is almost equal) but how can I do to receive as output a tuple with the two values? let rec max_list xs = match xs with | [] -> failwith "xs" "Empty list" | [x] -> x | x1::x2::xs' ->