f#

How to create a recursive data structure value in (functional) F#?

a 夏天 提交于 2020-01-01 09:10:12
问题 How can a value of type: type Tree = | Node of int * Tree list have a value that references itself generated in a functional way? The resulting value should be equal to x in the following Python code, for a suitable definition of Tree: x = Tree() x.tlist = [x] Edit : Obviously more explanation is necessary. I am trying to learn F# and functional programming, so I chose to implement the cover tree which I have programmed before in other languages. The relevant thing here is that the points of

Is F# a usable language for .net windows development

僤鯓⒐⒋嵵緔 提交于 2020-01-01 08:40:43
问题 I have been hearing about F# and Microsoft now have a guy who is blogging and coding away in redmond somewhere about it. Can you really write GUI code from F# (I'd love to see an example of say adding a button to a form and subscribing to the onclick event for instance) Does F# have full access to all of .Net? I'm honestly curious and I know I could google but I'd love to hear from someone who is really using the language. 回答1: Yes, you can certainly write WinForms apps - although you wouldn

Does Async.StartChild have a memory leak?

蓝咒 提交于 2020-01-01 07:42:06
问题 When I run the following test (built with F#2.0) I get OutOfMemoryException. It takes about 5 min to reach exception on my system (i7-920 6gb ram if it was running as x86 process), but in any case we can see how memory is growing in task manager. module start_child_test open System open System.Diagnostics open System.Threading open System.Threading.Tasks let cnt = ref 0 let sw = Stopwatch.StartNew() Async.RunSynchronously(async{ while true do let! x = Async.StartChild(async{ if (Interlocked

Does Async.StartChild have a memory leak?

烈酒焚心 提交于 2020-01-01 07:41:08
问题 When I run the following test (built with F#2.0) I get OutOfMemoryException. It takes about 5 min to reach exception on my system (i7-920 6gb ram if it was running as x86 process), but in any case we can see how memory is growing in task manager. module start_child_test open System open System.Diagnostics open System.Threading open System.Threading.Tasks let cnt = ref 0 let sw = Stopwatch.StartNew() Async.RunSynchronously(async{ while true do let! x = Async.StartChild(async{ if (Interlocked

How can I express a factorial n! with an F# function, recursive or otherwise?

风格不统一 提交于 2020-01-01 06:45:11
问题 A factorial of a natural number (any number greater or equal than 0 ) is that number multiplied by the factorial of itself minus one, where the factorial of 0 is defined as 1 . For example: 0! = 1 1! = 1 * 0! 2! = 2 * 1! 3! = 3 * 2! 4! = 4 * 3! 5! = 5 * 4! Another way of writing this is to multiply all natural numbers between 1 and n for n! : 5! = 1 * 2 * 3 * 4 * 5 How can I express this with a recursive function in F#? And should I do it with a recursive function? //Factorials! let factorial

Parsing: Lazy initialization and mutually recursive monads in F#

谁都会走 提交于 2020-01-01 06:44:09
问题 I've been writing a little monadic parser-combinator library in F# (somewhat similar to FParsec) and now tried to implement a small parser for a programming language. I first implemented the code in Haskell (with Parsec) which ran perfectly well. The parsers for infix expressions are designed mutually recursive. parseInfixOp :: Parser String -> Parser Expression -> Parser Expression parseInfixOp operatorParser subParser = ignoreSpaces $ do x <- ignoreSpaces $ subParser do op <- ignoreSpaces $

Parsing: Lazy initialization and mutually recursive monads in F#

风流意气都作罢 提交于 2020-01-01 06:44:08
问题 I've been writing a little monadic parser-combinator library in F# (somewhat similar to FParsec) and now tried to implement a small parser for a programming language. I first implemented the code in Haskell (with Parsec) which ran perfectly well. The parsers for infix expressions are designed mutually recursive. parseInfixOp :: Parser String -> Parser Expression -> Parser Expression parseInfixOp operatorParser subParser = ignoreSpaces $ do x <- ignoreSpaces $ subParser do op <- ignoreSpaces $

Automated F# Signature File (.fsi) Generation

丶灬走出姿态 提交于 2020-01-01 04:54:35
问题 I am working on a project that has a number of modules that I'd like to apply access control constraints to. I'd also like to have my project contain additional documentation on the type signatures of each function. I know that I can accomplish both of these tasks very easily via F# signature files. However, my project is large and contains many files, and I need a convenient way of generating a signature file for each one. I have been successful in generating individual signature files via

An implementation problem of F# Seq

旧巷老猫 提交于 2020-01-01 04:29:13
问题 I am digging into F# source code recently. in Seq.fs: // Binding. // // We use a type defintion to apply a local dynamic optimization. // We automatically right-associate binding, i.e. push the continuations to the right. // That is, bindG (bindG G1 cont1) cont2 --> bindG G1 (cont1 o cont2) // This makes constructs such as the following linear rather than quadratic: // // let rec rwalk n = { if n > 0 then // yield! rwalk (n-1) // yield n } After seeing the above code, I tested two code: let

How to achieve Asynchrony instead of Parallelism in F#

筅森魡賤 提交于 2020-01-01 03:18:49
问题 (Sticking to a common example with async fetch of many web pages) How would I spin off multiple (hundreds) of web page requests asynchronously, and then wait for all requests to complete before going to the next step? Async.AsParallel processes a few requests at a time, controlled by number of cores on the CPU. Grabbing a web page is not a CPU-bound operation. Not satisfied with the speedup of Async.AsParallel, I am looking for alternatives. I tried to connect the dots between Async