f#

Pattern matching by function call

邮差的信 提交于 2019-12-11 03:43:41
问题 F# assigns function arguments via pattern matching. This is why // ok: pattern matching of tuples upon function call let g (a,b) = a + b g (7,4) works: The tuple is matched with (a,b) and a and b are available directly inside f. Doing the same with discriminated unions would be equally beneficial, but I cannot get it to done: // error: same with discriminated unions type A = | X of int * int | Y of string let f A.X(a, b) = a + b // Error: Successive patterns // should be separated by spaces

type inference on abstract type with a tuple

限于喜欢 提交于 2019-12-11 03:42:50
问题 Based on this kvb's answer, this code compiles (F#4) and runs : type Untupler = abstract Apply : 'u * 'u -> 'u let myotherFun arg1 arg2 = printfn "myotherFun result is : %A %A" arg1 arg2 let myFunction tup1 tup2 (i:Untupler) = myotherFun (i.Apply tup1) (i.Apply tup2) let reskvb = myFunction (1,2) ("Hello","World") { new Untupler with member __.Apply (x,y) = snd (x,y) } But if the last line is replaced by the initial answer : let reskvb = myFunction (1,2) ("Hello","World") { new Untupler with

module vs type behavior difference on using F# lambda as actual argument to formal parameter that expects System.Func

自作多情 提交于 2019-12-11 03:37:47
问题 Assume I have some library code like open System module Foo = let Invoke1 (action : Func<string>) = () let Invoke2 (action : Func<int, string>) = () let Invoke3 (key : int, add : Func<int, string>, update: Func<int, string, string>) = () let Invoke4 (key : int) (add : Func<int, string>) (update: Func<int, string, string>) = () type Bar = static member Invoke1 (action : Func<string>) = () static member Invoke2 (action : Func<int, string>) = () static member Invoke3 (key : int, add : Func<int,

F# function changes type when compiled with standalone switch and referenced from another project

僤鯓⒐⒋嵵緔 提交于 2019-12-11 03:33:41
问题 In a Visual Studio project for an F# library I have defined a function as let inline Estimate (s : ^a seq) (f : float) (w : int) : float * float = .. The type of Estimate is val Estimate : s:seq<'a> -> f:float -> w:int -> float*float Calling Estimate from a script within that project works as expected. Now if I compile the project with the --standalone switch and reference the output DLL from another project, Estimate is shown to be Estimate<'a,'a>(s: Collections.Generic.IEnumerabls<'a>, f:

FSC: Error FS2024: Static linking may not use assembly that targets different profile

泄露秘密 提交于 2019-12-11 03:29:23
问题 F# is my first programming language. I use MS Visual Studio 2013, .NET Framework 4.5. For my personal coding project, these are the references I have included: FSharp.Data.TypeProviders Microsoft.Experimental.Collections Newtonsoft.Json System System.Data System.Data.Linq System.Runtime.Serialization System.Xml I received the error message mentioned in the title of this post. I tried the solution mentioned here, but I could not install the latest Visual F# Tools Build, apparently because "A

Classes created in F# serialized incorrectly in a C# WebApi/MVC project

时光毁灭记忆、已成空白 提交于 2019-12-11 03:26:08
问题 I created a class in FSharp like so: type Account() = class let mutable amount = 0m let mutable number = 0 let mutable holder = "" member this.Number with get () = number and set (value) = number <- value member this.Holder with get () = holder and set (value) = holder <- value member this.Amount with get () = amount and set (value) = amount <- value end When I reference the project from my C# WebAPI/MVC application like this [HttpGet] public Account Index() { var account = new Account();

Calling generic function with 'params' from F# (Observable.StartWith)

馋奶兔 提交于 2019-12-11 03:21:52
问题 Edit : Note that, as Daniel and latkin noted in an answer and a comment below, this question involved a bug in F# that seems to have been fixed in early 2014. I'm trying to write a curried wrapper for Observable.StartWith. I'm using the prerelease Reactive Extensions 2.0, and the VS11 beta. My desired result would be startWith : 'a -> IObservable<'a> -> IObservable<'a> . The obvious implementation would be something like: let startWith (value : 'a) (observable : IObservable<'a>) : IObservable

Mocking Non-Standard Events in F# Foq

萝らか妹 提交于 2019-12-11 03:20:17
问题 I'm new to F#, and I'm putting myself through some exercises to learn the language. The one I'm currently trying to do is to write a unit test for a custom Castle.Windsor Facility, and I am trying to Mock the Kernel to raise a "ComponentRegistered" event. The tools I'm using are FsUnit/xUnit/Foq. My Code: let event = Event<_,_>() let kernel = Mock<IKernel>() .SetupEvent(fun k -> <@ k.ComponentRegistered @>) .Publishes(event.Publish) .Create() Error Message: Error 4 The event

F# Type Provider Dependent Nested Types

旧时模样 提交于 2019-12-11 03:19:08
问题 I am trying to build a TypeProvider where nested ProvidedProperty is generated based on parent's type value. A result I want to have is following #r @"bin/Debug/library.dll" open Library.TypeProviders type sdmx = SdmxDataProvider<WsEntryPoint=""> let dataflows = sdmx.GetDataFlowsContext() let a = dataflows.A.A1 // A1,A2,A3 < should be generated based on A let b = dataflows.B.B1 // B1,B2,B3 < should be generated based on B let c = dataflows.C.C1 // C1,C2,C3 < should be generated based on C I

F# Assert.AreEquals fails with two literals

笑着哭i 提交于 2019-12-11 03:08:22
问题 I have the following unit test: open System open System.Collections.Generic open Microsoft.VisualStudio.TestTools.UnitTesting [<TestClass>] type Test_Spectra () = let standard = new Standard1() [<TestMethod>] member x.LightTransmittance () = let input = Test_Spectra.TestSprectra1 let expected = 0.32728222797751 let actual = standard.LightTransmittance(input) Assert.AreEqual(expected, actual) When I run the unit test it fails, however the values for 'expected' and 'actual' are equal: Expected