f#

FSharp project build fails in MSBuild in TeamCity

余生颓废 提交于 2019-12-23 16:15:26
问题 I have the following setup described here (TeamCity with MSBuild and F# 3.1 Tools installed). I have a number of projects in my solution, among which also a F# project. Everything builds fine in Visual Studio, but when I try to build it with MSBuild on my TeamCity server (which does not have VS installed) it throws the following build error on a project that references my FSharp project : "C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\MY_SOLUTION.sln.teamcity" (TeamCity_Generated_Build target)

F# adding polynomials recursively

一曲冷凌霜 提交于 2019-12-23 15:45:00
问题 I'm trying to write a function in F# that adds polynomials recursively. My polynomials can be represented as a list of tuples. For example, 2x^4 + 3x^2 + x + 5 is equal to [(2.0,4);(3.0,2);(1.0,1);(5.0,0)] All polynomials are properly structured (no repeated terms with the same degree, no terms with zero coefficients unless it is the zero polynomial, terms sorted by decreasing exponent no empty input list). I'm having trouble doing this. Here is my code type term = float * int type poly =

F# comparing discriminated unions' by case identifier

﹥>﹥吖頭↗ 提交于 2019-12-23 15:43:20
问题 Is there a way to compare discriminated unions by their case-identifiers in F#? type MyUnion = | MyString of string | MyInt of int let x = MyString("hello") let y = MyString("bye") let z = MyInt(25) let compareCases a b = // compareCases x y = true // compareCases x z = false // compareCases y z = false How do I implement compareCases function in a generic way? I.e. something like the following, but more generic (reflection is ok): let compareCases a b = match a with | MyString(_) -> match b

Preserving Field names across the F#/C# boundary

久未见 提交于 2019-12-23 15:28:37
问题 As a learning exercise, I am doing some data analysis on a 5000-line csv file using F# and F#'s type-provider functionality. When I use the type-provider-generated type in f#, naturally the header rows of the csv file become the field names of the type. type restaurantCsv = CsvProvider<"C:\Users\Paul\Desktop\HealthDepartment\RestaurantRatings2013.csv",HasHeaders=true> type RawInspectionData(filename : string) = member this.allData = restaurantCsv.Load(filename) member public this

How to convert F# function to non-generic System.Action?

风流意气都作罢 提交于 2019-12-23 15:19:47
问题 Just as in title. I have an existing C# library, and I must access it using F# interop. One of the methods takes a non-generic System.Action delegate as a parameter. How can I convert F# function (i.e. unit->unit ) to that delegate? While trying to use direct cast, a following error occurs: Multiple types exist called 'Action', taking different numbers of generic parameters. Provide a type instantiation to disambiguate the type resolution, e.g. 'Action<_,_,_,_,_,_,_,_,_>'. 来源: https:/

how do i translate this Haskell to F#?

不打扰是莪最后的温柔 提交于 2019-12-23 15:14:42
问题 I'm trying to learn F# by translating some Haskell code I wrote a very long time ago, but I'm stuck! percent :: Int -> Int -> Float percent a b = (fromInt a / fromInt b) * 100 freqs :: String -> [Float] freqs ws = [percent (count x ws) (lowers ws) | x <- ['a' .. 'z']] I've managed this: let percent a b = (float a / float b) * 100. although i dont like having to have the . after the 100. What is the name of the operation I am performing in freqs , and how do I translate it to F#? Edit: count

Under what conditions is unit a type?

假装没事ソ 提交于 2019-12-23 15:11:44
问题 Before this gets marked as a duplicate: I'm aware that this question is related to various questions about compilation errors when using unit as a type argument. Some examples: Why is unit treated differently by the F# type system when used as a generic interface argument? F# interface inheritance failure due to unit Using unit as Type Parameter and overriding methods These are all running into a problem similar to this one: type Interface<'a> = abstract member MyFunc : unit -> 'a let

int -> int list is not compatible with type int -> IEnumerable<'a>

南笙酒味 提交于 2019-12-23 14:39:50
问题 Given: open System.Linq this is an acceptable expression: [2; 3; 4].SelectMany(fun n -> { 1..n }) however this is not: [2; 3; 4].SelectMany(fun n -> [ 1..n ]) The error message says: int -> int list is not compatible with type int -> System.Collections.Generic.IEnumerable<'a> F# is rejecting the expression because the function is returning an int list . Consider this C# program which does something similar: using System; using System.Collections.Generic; using System.Linq; namespace

int -> int list is not compatible with type int -> IEnumerable<'a>

妖精的绣舞 提交于 2019-12-23 14:38:52
问题 Given: open System.Linq this is an acceptable expression: [2; 3; 4].SelectMany(fun n -> { 1..n }) however this is not: [2; 3; 4].SelectMany(fun n -> [ 1..n ]) The error message says: int -> int list is not compatible with type int -> System.Collections.Generic.IEnumerable<'a> F# is rejecting the expression because the function is returning an int list . Consider this C# program which does something similar: using System; using System.Collections.Generic; using System.Linq; namespace

Verifying a set of objects have been mapped correctly

纵饮孤独 提交于 2019-12-23 13:24:36
问题 I'm looking for a clean set of ways to manage Test Specific Equality in F# unit tests . 90% of the time, the standard Structural Equality fits the bill and I can leverage it with unquote to express the relation between my result and my expected . TL;DR "I can't find a clean way to having a custom Equality function for one or two properties in a value which 90% of is well served by Structural Equality, does F# have a way to match an arbitrary record with custom Equality for just one or two of