f#

How to capture output with XUnit 2.0 and FSharp style tests

穿精又带淫゛_ 提交于 2019-12-06 20:36:05
问题 Normally I write my unit tests in F# as open Swensen.Unquote open Xunit module MyTests = [<Fact>] let ``SomeFunction should return 10`` () = let a = SomeFunction() test <@ a = 10 @> [<Fact>] let ``SomeOtherFunction should return 11`` () = let a = SomeFunction() test <@ a = 11 @> If I wish to log to the console from xunit ( according to http://xunit.github.io/docs/capturing-output.html ) one needs to write a constructor that takes an ITestOutputHelper and then use that instead of Console

F#, Nominative or Structural Typed

岁酱吖の 提交于 2019-12-06 20:20:31
问题 Does F# have a Nominative Type System or a Structural Type System? I know that OCaml is structurally typed, though F# doesn't seems to be so, is this correct? 回答1: F# is nominative. You can do a few structural tricks via some exotic mechanisms, but the type system of the language is primarily nominative. 来源: https://stackoverflow.com/questions/3137512/f-nominative-or-structural-typed

How is one supposed to use the F# SqlDataConnection TypeProvider with an App.Config file?

泄露秘密 提交于 2019-12-06 20:11:29
问题 I am using the type expression: type dbSchema = SqlDataConnection<ConnectionStringName="X1", ConfigFile="App.config"> This works great at compile time (I have full access to all the db types), but it fails at run time. I presume it's because the config file generated in the console application's bin directory is named something else, such as MyAppName.exe.config , and therefore the App.config file is not found. Certainly, for an ASP.NET MVC type app that uses web.config , there's no issue

Is replacing a list element an anti-pattern?

落花浮王杯 提交于 2019-12-06 20:07:22
问题 I have a module that works on paths represented as lists. Most of the functions do typical recursive list processing, but now I need one that sometimes mutates a path. So, I wrote this replace function: module List = let replace f sub xs = let rec finish acc = function | [] -> acc | x::xs -> finish (x::acc) xs let rec search acc = function | [] -> None | x::xs -> if f x then Some(finish ((sub x)::xs) acc) else search (x::acc) xs search [] xs which works like this: let xs = List.init 10 id let

F# PSeq.iter does not seem to be using all cores

时光毁灭记忆、已成空白 提交于 2019-12-06 19:16:26
问题 I've been doing some computationally intensive work in F#. Functions like Array.Parallel.map which use the .Net Task Parallel Library have sped up my code exponentially for a really quite minimal effort. However, due to memory concerns, I remade a section of my code so that it can be lazily evaluated inside a sequence expression (this means I have to store and pass less information). When it came time to evaluate I used: // processor and memory intensive task, results are not stored let

Literal Attribute not working

旧巷老猫 提交于 2019-12-06 18:56:45
问题 After reading Chris' answer to F# - public literal and the blog post at http://blogs.msdn.com/b/chrsmith/archive/2008/10/03/f-zen-the-literal-attribute.aspx I don't get why the following is not working: [<Literal>] let one = 1 [<Literal>] let two = 2 let trymatch x = match x with | one -> printfn "%A" one | two -> printfn "%A" two | _ -> printfn "none" trymatch 3 This keeps printing "3", although I think it shouldn't. What is it that I don't see here? 回答1: I think that literals need to be

Impredicative polymorphism in F#

北城以北 提交于 2019-12-06 18:55:45
问题 OCaml's Hindley-Milner type system does not allow for impredicative polymorphism (à la System-F), except through a somewhat recent extension for record types. The same applies to F#. It however is sometimes desirable to translate programs written with impredicative polymorphism (e.g. Coq) into such languages. The solution for Coq's extractor to OCaml is to (sparingly) use Obj.magic , which is a kind of universal unsafe cast. This works because in OCaml's runtime system, all values have the

how to pause the console in F# language

独自空忆成欢 提交于 2019-12-06 18:55:29
问题 Please tell me how I can pause the console window when running the program in F#. open System let myList = [0..9] let myFunction = for n in myList do Console.WriteLine(n) myFunction 回答1: I am guessing that you want the console to display the output after the program execution finishes. You could put this line in the end of your snippet Console.ReadKey() |> ignore to 'pause' the console in that sense. 回答2: // When running in debug mode and using Visual Studio to run the program, // one may

Why there is no List.skip and List.take?

无人久伴 提交于 2019-12-06 18:31:40
问题 Why there is no List.skip and List.take? There is of course Seq.take and Seq.skip, but they does not create lists as a result. One possible solution is: mylist |> Seq.skip N |> Seq.toList But this creates first enumerator then a new list from that enumerator. I think there could be more direct way to create a immutable list from immutable list. Since there is no copying of elements internally there are just references from the new list to the original one. Other possible solution (without

F# Optional Record Field

ⅰ亾dé卋堺 提交于 2019-12-06 18:31:12
问题 I have a F# record type and want one of the fields to be optional: type legComponents = { shares : int<share> ; price : float<dollar / share> ; totalInvestment : float<dollar> ; } type tradeLeg = { id : int ; tradeId : int ; legActivity : LegActivityType ; actedOn : DateTime ; estimates : legComponents ; ?actuals : legComponents ; } in the tradeLeg type I would like the the actuals field to be optional. I can't seem to figure it out nor can I seem to find a reliable example on the web. It