f#

F# using match to validate parameters

◇◆丶佛笑我妖孽 提交于 2019-12-11 01:52:31
问题 I'm learning F#. I want to know best practices for validating input parameters. In my naivety I had thought I could do something like this: let foo = match bar with | <test for valid> -> bar | _ -> "invalid" of course that doesn't work due to mismatching types. So I'd like to see the patterns experienced F# programmers use for this sort of thing. match? If/then/else? Something else? 回答1: You are having problems because you are trying to bind a value to something that could be two possible

Excel-DNA: F# Error Initialization [Error] Method not registered

℡╲_俬逩灬. 提交于 2019-12-11 01:48:51
问题 As a neophyte F# developer, I am trying to create a simple Excel-DNA function as follows: [<ExcelFunction(Name="ACount", Description="Count items", Category="Misc Functions", IsThreadSafe = true)>] let aCount (range: _[]) (filter: string) = let result = Seq.ofArray range |> Seq.filter (fun x -> x = filter) |> Seq.length result but it generates the following error on loading to Excel 2016 (64-bit): Initialization [Error] Method not registered - unsupported signature, abstract or generic: What

Seq.map from one list to populate another list of different type?

旧街凉风 提交于 2019-12-11 01:46:58
问题 This question is in follow up to an earlier question, Preserving Field names across the F#/C# boundary Because of the current limitation encountered with F# type providers (see the earlier question), I want to map the type-provider-generated list to my own list of records, in which the record is, in part, type inspection = { inspectionID : string; inspectorID : int; EstablishmentID : string; EstablishmentName : string; // other members elided } I think the way to do this will use Seq.map, but

How to move from external function to functional lens

别说谁变了你拦得住时间么 提交于 2019-12-11 01:45:20
问题 On my journey to start getting better with functional programming, I discovered, with the help of a member of the SO family, what lens. I even made some research on it with the links down below to understand more about them. https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/basic-lensing http://fluffynukeit.com/how-functional-programming-lenses-work/ https://medium.com/@dtipson/functional-lenses-d1aba9e52254#.27yw4gnwk With all that knowledge, I thought I could

Mix values from two List using recursion

戏子无情 提交于 2019-12-11 01:39:33
问题 I want to mix values using two lists: List1 : [3; 2; 8; 1; 9; 3; 6] List2: [5; 7; 0] Output : [3; 5; 2; 7; 8; 0; 1; 9; 3; 6] I only found info about list with the same length what about this example when i have diffrent ? The same length : let rec mix =function |(x::xs,y::ys) -> x::y::(mix (xs,ys)) |([],[]) -> [] | _ -> failwith "mix:param";; mix ([3;2;8;1;9;3;6], [5; 7; 0]) ;; 回答1: The best way to break this down is by considering each possible case for a particular step. You currently have:

What is the F# interactive window good for?

巧了我就是萌 提交于 2019-12-11 01:38:36
问题 Am I able to script macros here? Maybe process some text? I may be interest in learning F# if this window provided the ability to process the current document, etc. I have googled and found tutorials on learning F#, writing programs in F#, but nothing on what the F# interactive window is good for in VS. EDIT: Sounds like a rant yes. Is it? No. I love scripting. I just wrote a ruby script to implement an interface on a bunch of existing POCO's, that I couldn't easily figure out how to do with

Recursive formula for skewness in F#

余生颓废 提交于 2019-12-11 01:34:05
问题 I am trying to make a skewness function in F# using Knuth's recursive formula, based on the formula for the variance in Jon Harrop's F# for scientists. Here is my code, (with an auxilliary function) let skewness_aux (m, m2, m3, k) x = let m' = m + (x - m)/k let m2' = m2 + ((x - m)*(x - m)*(k-1.0))/k m', m2', m3 + (x-m)*(x-m)*(x-m)*(k-1.0)*(k-2.0)/(k*k)-(3.0*(x-m)*m2)/k, k + 1.0;; let skewness xs = let _, m2, m3, n2 = Seq.fold skewness_aux (0.0, 0.0, 0.0, 1.0) xs (sqrt(n2) * m3)/(sqrt (m2*m2

Running F# xUnit Fact from TestDriven.NET reporting “It looks like you're trying to execute an xUnit.net unit test.”

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 01:29:44
问题 I am trying to run xUnit tests (from an F# module, if it makes any difference) using TestDriven.NET, but whatever I do I get this error: It looks like you're trying to execute an xUnit.net unit test. For xUnit 1.5 or above (recommended): Please ensure that the directory containing your 'xunit.dll' reference also contains xUnit's test runner files ('xunit.dll.tdnet', 'xunit.runner.tdnet.dll' etc.) For earlier versions: You need to install support for TestDriven.Net using xUnit's 'xunit

Recursion in F# | What's happening?

社会主义新天地 提交于 2019-12-11 01:29:13
问题 I've found a basic example of an f# recursive function that takes a list and returns a list of only even integers. I understand it for the most part, but there's a little i'm confused about. let numbers = [1..4] let rec even ls = match ls with | [] -> [] |head :: tail when head % 2 = 0 -> head :: even tail |_::tail -> even tail The line that matches head confuses me. This is how I read it. Append head to tail when head is even, then call even tail again. Because we appended head to tail,

F# code quotation invocation, performance, and run-time requirements

大城市里の小女人 提交于 2019-12-11 01:26:51
问题 Here are 4 deeply related questions about F# code quotations - How do I invoke an F# code quotation? Will it be invoked in a manner less efficient than if it were just a plain old F# lambda? to what degree? Will it require run-time support for advanced reflection or code-emitting functionality (which is often absent or prohibited from embedded platforms I am targeting)? 回答1: Quotations are just data, so you can potentially "invoke" them in whatever clever way you come up with. For instance,