f#

Fable F# > js compile multiple .fsx files

戏子无情 提交于 2019-12-22 06:09:37
问题 How can I compile multiple .fsx files using Fable? I (naively) tried to just pass an array of them in the fable.config file like this: { "outDir": "app", "projFile":["app/index.fsx", "app/testmod.fsx"], "sourceMaps": true, "targets": { "production": { "sourceMaps": false } } } but get the warning: ARG ERROR: TypeError: Path must be a string. Received [ 'app/index.fsx', 'app/testmod.fsx' ] I know I could make a full-blown .fsproj file and point the fable compiler to that but it seems like

Use Post or PostAndAsyncReply with F#'s MailboxProcessor?

微笑、不失礼 提交于 2019-12-22 05:53:23
问题 I've seen different snippets demonstrating a Put message that returns unit with F#'s MailboxProcessor . In some, only the Post method is used while others use PostAndAsyncReply , with the reply channel immediately replying once the message is being processed. In doing some testing, I found a significant time lag when awaiting the reply, so it seems that unless you need a real reply, you should use Post . Note: I started asking this in another thread but thought it useful to post as a full

Critique of immutable classes with circular references design, and better options

耗尽温柔 提交于 2019-12-22 05:33:41
问题 I have a factory class that creates objects with circular references. I'd like them to be immutable (in some sense of the word) too. So I use the following technique, using a closure of sorts: [<AbstractClass>] type Parent() = abstract Children : seq<Child> and Child(parent) = member __.Parent = parent module Factory = let makeParent() = let children = ResizeArray() let parent = { new Parent() with member __.Children = Seq.readonly children } [Child(parent); Child(parent); Child(parent)] |>

How to pass LinQ Expressions from F# to C# code

泄露秘密 提交于 2019-12-22 05:30:11
问题 ReactiveUI has methods with signitures like public static ReactiveUI.ObservableAsPropertyHelper<TRet> ObservableToProperty<TObj, TRet>( this TObj This, System.IObservable<TRet> observable, System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, TRet initialValue = null, System.Reactive.Concurrency.IScheduler scheduler = null ) In F# How would I construct an object like System.Linq.Expressions.Expression<System.Func<TObj, TRet>> property, In C# I would do something like this

Type inference failing on generic type with static member constraint

我是研究僧i 提交于 2019-12-22 05:23:22
问题 I have defined the following type (simplified from code): type Polynomial<'a when 'a :(static member public Zero : 'a) and 'a: (static member (+): 'a*'a -> 'a) and 'a : (static member (*): 'a*'a -> 'a) > = | Polynomial of 'a list with static member inline (+) (x: Polynomial<'a> , y : Polynomial<'a>) : Polynomial<'a>= match x,y with |Polynomial xlist, Polynomial ylist -> let longer, shorter = if xlist.Length> ylist.Length then xlist, ylist else ylist, xlist let shorterExtended = List.append

Using a F# event and asynchronous in multi-threaded code

断了今生、忘了曾经 提交于 2019-12-22 05:08:36
问题 I'm working a lot with asynchronous workflows and agents in F#. While I was going a little bit deeper into events I noticed that the Event<_>() type is not thread-safe. Here I'm not talking about the common problem of raising an event. I'm actually talking about subscribing and removing/disposing from an event. For testing purposes, I have written this short program: let event = Event<int>() let sub = event.Publish [<EntryPoint>] let main argv = let subscribe sub x = async { let mutable

Debugging F# in Xamarin Studio 4.0.3 throws an error

心已入冬 提交于 2019-12-22 04:58:08
问题 I have installed Xamarin Studio 4.0.1 on Windows 8 x64 from http://monodevelop.com/Download . When I ran Xamarin, it got updated to 4.0.3. I have installed F# bindings. I have created new F# console project. When I run it, it works fine. When I set a break-point and run it, I get the following error. Any idea, why that happens? System.Runtime.InteropServices.COMException (0x80070032): The request is not supported. (Exception from HRESULT: 0x80070032) at Microsoft.Samples.Debugging.CorDebug

F# the namespace or module 'XXXX' is not defined

╄→尐↘猪︶ㄣ 提交于 2019-12-22 04:34:05
问题 I'm trying to create a basic ASP.net f# application and when I'm trying to reference the Youtube .net API I'm getting a "The namespace or module 'Google' is not defined" in my code behind file. I've used the default ASP web forms template in Visual Studio, removed all of the contents, then loaded in the examples from Expert F#, Chapter 14. The default examples run fine, the problem only occurs when loading the Google API. The API works fine when I load it through an f# console application.

How do I await an async method in F#

旧街凉风 提交于 2019-12-22 04:08:13
问题 How do I await an async method in F#? I have the following code: type LegoExample() = let brick = Brick(BluetoothCommunication("COM3")) let! result = brick.ConnectAsync(); Error: Unexpected binder keyword in member definition Note, I reviewed the following link: However, I only observe the functional technique and not the OOP technique. 回答1: you get the error because the let! construct (just like the do! ) needs to be placed inside a computational workflow (like async { ...} but there are

why do continuations avoid stackoverflow?

耗尽温柔 提交于 2019-12-22 03:52:54
问题 I've been trying to understand continuations / CPS and from what I can gather it builds up a delayed computation, once we get to the end of the list we invoke the final computation. What I don't understand is why CPS prevents stackoverflow when it seems analogous to building up a nested function as per the naive approach in Example 1. Sorry for the long post but tried to show the idea (and possibly where it goes wrong) from basics: So: let list1 = [1;2;3] Example 1: "Naive approach" let rec