f#

F# special quotes? (##)

坚强是说给别人听的谎言 提交于 2020-01-10 18:32:38
问题 I just ran across http://frankniemeyer.blogspot.com/2010/04/minimalistic-native-64-bit-array.html Which contains the line (# "sizeof !0" type('T) : nativeint #) I believe the technical phrase is "what the heck?" I have never in my (~8 months) of F# programming run across something even resembling that... FSI tells me something about deprecated constructs, used only for F# libs... And google with (# does uh...well, not much Any direction in this? 回答1: This is the notation for inline IL

StackOverflow in continuation monad

筅森魡賤 提交于 2020-01-10 10:42:10
问题 Using the following continuation monad: type ContinuationMonad() = member this.Bind (m, f) = fun c -> m (fun a -> f a c) member this.Return x = fun k -> k x let cont = ContinuationMonad() I fail to see why the following gives me a stack overflow: let map f xs = let rec map xs = cont { match xs with | [] -> return [] | x :: xs -> let! xs = map xs return f x :: xs } map xs id;; let q = [1..100000] |> map ((+) 1) While the following doesn't: let map f xs = let rec map xs = cont { match xs with |

StackOverflow in continuation monad

最后都变了- 提交于 2020-01-10 10:41:27
问题 Using the following continuation monad: type ContinuationMonad() = member this.Bind (m, f) = fun c -> m (fun a -> f a c) member this.Return x = fun k -> k x let cont = ContinuationMonad() I fail to see why the following gives me a stack overflow: let map f xs = let rec map xs = cont { match xs with | [] -> return [] | x :: xs -> let! xs = map xs return f x :: xs } map xs id;; let q = [1..100000] |> map ((+) 1) While the following doesn't: let map f xs = let rec map xs = cont { match xs with |

StackOverflow in continuation monad

荒凉一梦 提交于 2020-01-10 10:41:23
问题 Using the following continuation monad: type ContinuationMonad() = member this.Bind (m, f) = fun c -> m (fun a -> f a c) member this.Return x = fun k -> k x let cont = ContinuationMonad() I fail to see why the following gives me a stack overflow: let map f xs = let rec map xs = cont { match xs with | [] -> return [] | x :: xs -> let! xs = map xs return f x :: xs } map xs id;; let q = [1..100000] |> map ((+) 1) While the following doesn't: let map f xs = let rec map xs = cont { match xs with |

F# priority queue

淺唱寂寞╮ 提交于 2020-01-10 08:49:48
问题 Does the F# library include a priority queue? Else can someone point to me an implementation of priority queue in F#? 回答1: There's an implementation of a binomial heap here which is a common data structure for implementing priority queues. 回答2: Take a look at http://lepensemoi.free.fr/index.php/tag/data-structure for a whole bunch of F# implementations of various data structures. 回答3: FSharpx.Collections includes a functional Heap collection https://github.com/fsharp/fsharpx/blob/master/src

How do I create a Linq expression tree with an F# lambda?

◇◆丶佛笑我妖孽 提交于 2020-01-09 10:02:43
问题 Here's what can be done in C# - var two = 2; System.Linq.Expressions.Expression<System.Func<int, int>> expr = x => x * two; expr.Compile().Invoke(4); // returns 8 I wish to do the precise equivalent in F#. Here's what I tried, but did not compile - let two = 2 let expr = (fun x -> x * two) : System.Linq.Expressions.Expression<System.Func<int, int>> expr.Compile().Invoke(4) // desired to return 8 Perhaps predictably, compilation fails on line 2 with the following error - "This function takes

Type provider and big XML file

百般思念 提交于 2020-01-06 20:13:14
问题 I am wondering what are the good practices in using type provider in F#, I have an XML file (25Mo+), I thought it will not be an issue but my Visual Studio is suffering a lot loll. What is usually the good practice, to define a complete template of the XML with the minimum of data and Load the content later ? And if we load a big file with optional node, the type will be inferred by the most complete one ? Thanks 回答1: The XmlProvider type provider is based on XDocument (LINQ to XML), so it

The value or constructor 'DotCoverNUnit' is not defined

我只是一个虾纸丫 提交于 2020-01-06 16:20:46
问题 We're using Fake and I'd like to run DotCover after our Build target. It's alway telling me: C:\Users\xxxxx\Dev>FAKE\tools\Fake build.fsx F# Interactive for F# 3.1 (private) Freely distributed under the Apache 2.0 Open Source License For help type #help;; > [Loading C:\Users\xxxxx\Dev\build.fsx] build.fsx(8,1): error FS0039: The value or constructor 'DotCoverNUnit' is not defined My short simple "test" script #r @"FAKE/tools/FakeLib.dll" open Fake DotCoverNUnit dotCoverOptions nUnitOptions

The value or constructor 'DotCoverNUnit' is not defined

≯℡__Kan透↙ 提交于 2020-01-06 16:20:01
问题 We're using Fake and I'd like to run DotCover after our Build target. It's alway telling me: C:\Users\xxxxx\Dev>FAKE\tools\Fake build.fsx F# Interactive for F# 3.1 (private) Freely distributed under the Apache 2.0 Open Source License For help type #help;; > [Loading C:\Users\xxxxx\Dev\build.fsx] build.fsx(8,1): error FS0039: The value or constructor 'DotCoverNUnit' is not defined My short simple "test" script #r @"FAKE/tools/FakeLib.dll" open Fake DotCoverNUnit dotCoverOptions nUnitOptions

F#: Iterating over a dictionary just returns itself?

こ雲淡風輕ζ 提交于 2020-01-06 14:35:07
问题 let h = dict [(1, 2), (3, 4)] Console.WriteLine(h.Count) for i in h do Console.WriteLine(i) gives me 1 [(1, 2), (3, 4)] Two questions. Firstly, why does iterating over a dict give me back a sequence which only has 1 item, the dict itself? There is probably some logic behind this that will also affect other things I end up trying to iterate over. What does this mean for all the other Seq members exposed by dict (Any(), All(), Aggregate(), etc.)? Secondly, is there a good way to iterate over