f#

Find maximum, minimum and average in F#

浪子不回头ぞ 提交于 2019-12-06 03:15:05
问题 I want to find maximum, minimum and average in an array without .NET in F#. I used this code but it is not working: let mutable max = 0 let arrX = [|9; 11; 3; 4; 5; 6; 7; 8|] for i in 0 .. arrX.Length - 2 do if (arrX.[i]) < (arrX.[i+1]) then max <- arrX.[i] printfn "%i" max 回答1: I fixed your code for max let mutable max = 0 let arrX= [|9; 11; 3; 4; 5; 6; 7; 8|] for i in 0 .. arrX.Length - 1 do if max < (arrX.[i]) then max <- arrX.[i] printfn "%i" max To find max, min and avg, using your

in F# on MAC OSX and Ubuntu I get an error running FSI in 4.0

混江龙づ霸主 提交于 2019-12-06 03:08:24
I need System.Numerics in F# EDIT I think the question is can fsi run with the 4.0 runtime and if so how do I configure it I run "mono /bin/Fsi" in the Fsharp 4.0 dir I get the following error in both OSX 10.6.4 and Ubuntu 10.1. I am sure I am missing a path or something Please note the paths are different on the MAC but I got the same error error FS0078: Unable to find the file 'System.Numerics.dll' in any of /opt/mono-2.8/lib/mono/2.0 /home/gary/Downloads/FSharp-2.0.0.0/v4.0/bin /home/gary/Downloads/FSharp-2.0.0.0/v4.0/bin/ On my MAcbook I copied the mono 4.0 bin dir to one of the above

F# XML Type Provider Common Elements

偶尔善良 提交于 2019-12-06 02:57:39
XSD specifications for XML files can share common elements. If I have several XML files that share a common element, is there a way to extract the common element without repeating the code for each XML file type? For example: There are a number of XML files defined via XSD, with a common description element, but different content structures elsewhere. The description has subelements with things like author, date, etc. When I create a type provider for each of the XML files, the types are different, so if I only want to extract the description section out of each, the code has to be copy pasted

How to use FsCheck to generate random numbers as input for property-based testing

自闭症网瘾萝莉.ら 提交于 2019-12-06 02:47:55
问题 I thought it's time to try out FsCheck but it proves tougher than I thought. There's a lot of documentation on Arb , generators and so on, but there doesn't seem to be any guidance in how to apply that knowledge. Or I'm just not getting it. What may make it harder to grasp is that the relation between tests, properties, generators, arbitraries, shrinking and, in my case, randomness (some tests automatically generate random data, others don't) is not clear to me. I don't have a Haskell

Integration of C#, F#, IronPython and IronRuby

半城伤御伤魂 提交于 2019-12-06 02:43:56
问题 I was told that the assembly files made from C# and F# source is interoperable as they are compiled into .NET assembly. Q1 : Does that mean that C# can call F# functions just like they are C# functions? Q2 : How about the IronPython and IronRuby? I don't see any assembly dll from the IronPython/IronRuby. Q3 : Is there any easy way to use IronPython/IronRuby functions from C# or F#? Any example code would be great. 回答1: 1) Yes. Using a simple example, in F#, I can invoke the main method of a C

F# Pattern Matching: Matching functions/lists of subtypes?

守給你的承諾、 提交于 2019-12-06 02:43:07
问题 let f (O: obj) = match O with | :? (obj -> list<obj>) -> "win" | :? list<obj> -> "list!" | _ -> "fail" Console.WriteLine(f(fun x -> ["lol"])) Console.WriteLine(f(["lol"])) prints "fail" twice, as I suppose it should, because I am giving i a function obj -> list<String> , which is not a obj -> list<obj> . Is there any way to make them match though? I could upcast each list into a list<obj> before making an anonymous function out of it, or I could upcast everything to obj before putting it into

Difficulty in writing Red Black Tree in F#

拈花ヽ惹草 提交于 2019-12-06 02:41:56
问题 I am writing a red black tree in F#. the code which I have written is below. I am facing 2 problems with this code The rules of balancing the tree state that when the tree has a XYr or rXY type of imbalance I must recolor the 2 parent nodes and IF the grand parent node is not ROOT of the tree then it should be recolored as well. The difficulty here is that in the recursive approach I only get the next node to work on.. so its hard to know what is the root node. IN order to solve the above, I

F# with sqlclr in a reasonably safe way and scripted assembly

送分小仙女□ 提交于 2019-12-06 02:32:05
There exist some blog posts about how to use F# with SQLCLR in SQL Server that are helpful: http://richardminerich.com/2015/12/a-safer-way-to-use-f-with-sql-clr/ , http://thelastexpression.blogspot.com/2012/04/f-agents-and-sqlclr.html , https://rojepp.wordpress.com/2011/08/03/f_on_sqlclr/ , Can the F# core libs be SQLCLR-approved? and for the C# approach: http://www.sqlservercentral.com/Authors/Articles/Solomon_Rutzky/294002/ I am wondering/hoping that with the passage of time there is a blog post out there, which I haven't been able to find yet or an answer here, which addresses how to use F#

Parsing int or float with FParsec

大兔子大兔子 提交于 2019-12-06 02:09:09
问题 I'm trying to parse a file, using FParsec, which consists of either float or int values. I'm facing two problems that I can't find a good solution for. 1 Both pint32 and pfloat will successfully parse the same string, but give different answers, e.g pint32 will return 3 when parsing the string "3.0" and pfloat will return 3.0 when parsing the same string. Is it possible to try parsing a floating point value using pint32 and have it fail if the string is "3.0" ? In other words, is there a way

How to obtain F# powerpack for F# 3.0

自作多情 提交于 2019-12-06 02:06:29
问题 I'm using VS11 Beta on Win 8 Consumer Preview. After install VS11 Beta I have F# 3.0 SDK installed. But I'm not able to find a compatible FSharp.PowerPack.dll as CodePlex only provides PowerPack for F# 2.0. Any idea how to deal with this? 回答1: You can compile the PowerPack sources on your own (against F# 3.0), to make your own copy of the library. Alternatively, I think a binding redirect in your final foo.exe.config, along the lines of https://stackoverflow.com/a/9648673/19299 but