f#

Async.TryCancelled doesn't work with Async.RunSynchronously

懵懂的女人 提交于 2019-12-21 06:45:15
问题 I try to create an agent that updates UI based on user interaction. If user clicks on a button, the GUI should be refreshed. The preparation of model takes a long time, so it is desirable that if user clicks on other button, the preparation is cancelled and the new one is started. What I have so far: open System.Threading type private RefreshMsg = | RefreshMsg of AsyncReplyChannel<CancellationTokenSource> type RefresherAgent() = let mutable cancel : CancellationTokenSource = null let

How to add and use custom context parameters during parsing with F# FsYacc?

十年热恋 提交于 2019-12-21 06:21:47
问题 I'm using FsLex and FsYacc for string parsing in F# application. During Abstract Syntax Tree (AST) creation parser has to do a decision how to create the AST (make different trees, throw an exception, etc). The parser behaviour must depend on several parameters. Here I've found that it is allowed to declare something like: %type < (context -> context) > toplevel But I could not find how to use this construction and during project compilation have "fsyacc.exe" exited with code 1." error The

How to do chained callbacks in F#?

烈酒焚心 提交于 2019-12-21 05:54:07
问题 In C# I am using the asynchronous versions of TcpListener/TcpClient, and I am chaining these via the callback method so that another Accept/Read is posted when the callback completes. Here is an example (untested): public void Start() { TcpListener listener = new TcpListener(IPAddress.Any, 3000); listener.Start(); PostAccept(listener); } private void PostAccept(TcpListener listener) { listener.BeginAcceptTcpClient(AcceptCallback, listener); } private void AcceptCallback(IAsyncResult ar) { var

Wrangling TryWith in Computation expressions

别说谁变了你拦得住时间么 提交于 2019-12-21 05:38:12
问题 (Having failed to 'grok' FParsec, I followed the advice I read somewhere and started trying to write a little parser myself. Somehow I spotted what looked like a chance to try and monadify it, and now I have N problems...) This is my 'Result' type (simplified) type Result<'a> = | Success of 'a | Failure of string Here's the computation expression builder type ResultBuilder() = member m.Return a = Success(a) member m.Bind(r,fn) = match r with | Success(a) -> fn a | Failure(m) -> Failure(m) In

Obtaining global roots from .NET programs

喜你入骨 提交于 2019-12-21 05:32:11
问题 I recently started using the ANTS profiling tools for production work. Aside from being amazed by their awesomeness, I couldn't help but wonder how they work. For example, one of the most useful features lets you visualize the global roots of a running program complete with the number of references to values of different types. How does this tool get hold of that information? 回答1: (Full disclosure: I'm on the Visual Studio Profiler team, but the below information is public) You can do this by

Why does this computation expression builder expect “unit” in my for loop?

佐手、 提交于 2019-12-21 05:19:04
问题 This is a follow-up question to this question. I'm trying to create a computation expression builder that accumulates a value through custom operations, and also supports standard F# language constructs at the same time. For the purposes of having a simple example to talk about, I'm using a computation expression that builds F# lists. Thanks to suggestions from kvb and Daniel I'm further along, but still having trouble with for loops. The builder: type Items<'a> = Items of 'a list type

Converting from m/s to km/h using F# Units of Measure

孤街醉人 提交于 2019-12-21 04:37:10
问题 I'm in the process of learning F# - and is currently looking into Units of Measure. I have a simple calculation returning meters per second, and I want to introduce a function converting it to kilometres per hour. My code looks like this: [<Measure>] type kg [<Measure>] type s [<Measure>] type m [<Measure>] type km [<Measure>] type h let msToKmph(speed : float<m/s>) = (float speed) * 3.6<km/h> let gravityOnEarth = 9.81<m/s^2> let heightOfJump = 3.5<m> let speedOfImpact = sqrt (2.0 *

Image analysis - fiber recognition

旧城冷巷雨未停 提交于 2019-12-21 04:32:14
问题 I am new to image analysis. Do you know how to binarize this image in such a way to get the fibers only? I have tried different threshold techniques etc, but I was not successful. I do not mind what tool I should use but I prefer .NET or Matlab . PS: I did not know where to put my answer, so I put it at StackOverflow. 回答1: Based on the comments, it seems you are having difficulty translating the proposed Mathematica solutions into MATLAB. Here is my attempt: @Nakilon solution %# read image I

Writing a service in F#

巧了我就是萌 提交于 2019-12-21 04:28:16
问题 I am back again, this time with a question on writing service in F#. I cannot seem to install the service using installutil. It gives me the following error. $ installutil atfwindowsservice.exe Microsoft (R) .NET Framework Installation utility Version 4.0.30319.18408 Copyright (C) Microsoft Corporation. All rights reserved. Running a transacted installation. Beginning the Install phase of the installation. See the contents of the log file for the C:\Dev\ATF\output\bin\Debug\atfwindowsservice

F#/JavaScript tool?

為{幸葍}努か 提交于 2019-12-21 04:20:58
问题 At a UG meeting I heard about a tool called "web sharper" or "web sharpener" or something like that which is supposed to make it easy to generate JavaScript from F#. Functional JavaScript or something like that. Unfortunately, I seem to have gotten the name wrong and I cannot find it. Does anyone know the name and have a link? 回答1: There are currently three projects that attempt to generate JavaScript from F#: Fable (updated 2019) is an open-source F# to JavaScript compiler with an active