f#

object expression and captured state in F#

放肆的年华 提交于 2019-12-10 14:56:33
问题 What makes the first implementation KO ? type IToto = abstract Toto : unit -> unit { new IToto with member this.Toto = fun () -> () } { new IToto with member this.Toto () = () } 回答1: In the compile representation, there is a difference between property of a function type, compiled as FSharpFunc<unit, unit> Toto { get; } , and a method taking unit and returning unit, compiled as unit Toto() . The first object expression implements a different interface: type IToto = abstract Toto : (unit ->

How to use TryScan in F# properly

◇◆丶佛笑我妖孽 提交于 2019-12-10 14:56:32
问题 I was trying to find an example about how to use TryScan , but haven't found any, could you help me? What I would like to do (quite simplified example): I have a MailboxProcessor that accepts two types of mesages. First one GetState returns current state. GetState messages are sent quite frequently The other UpdateState is very expensive (time consuming) - e.g. downloading something from internet and then updates the state accordingly. UpdateState is called only rarely. My problem is -

Windows 8 and F# [closed]

霸气de小男生 提交于 2019-12-10 14:55:19
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . So, since one cannot build metro style apps with F# and it isn’t possible to reference a F# library from within a metro style app,

F#: Implementing interface with function name the same as the keyword begin

淺唱寂寞╮ 提交于 2019-12-10 14:54:58
问题 I am trying to implement the IVector interface which is part of the Microsoft.VisualC.StlClr namespace. It has a member function begin(). If I try to implement the interface then it complains about "unexpected keyword 'begin' in object expression". Is this because begin is a keyword and I can't implement a member function with that name? B. 回答1: you can try to wrap it into backticks. IVector inteface is too big to implement it as sample, so example will be smaller - the code below compiles

How to Get the F# Name of a Module, Function, etc. From Quoted Expression Match

我的未来我决定 提交于 2019-12-10 14:53:14
问题 I continue to work on a printer for F# quoted expressions, it doesn't have to be perfect, but I'd like to see what is possible. The active patterns in Microsoft.FSharp.Quotations.Patterns and Microsoft.FSharp.Quotations.DerivedPatterns used for decomposing quoted expressions will typically provide MemberInfo instances when appropriate, these can be used to obtain the name of a property, function, etc. and their "declaring" type, such as a module or static class. The problem is, I only know

Is FSharp.Data.DesignTime .NET 4.5 only?

≡放荡痞女 提交于 2019-12-10 14:49:03
问题 I'm using FSharp.Data.1.1.10 in a .NET 4.0 project, and when I add FSharp.Data with Nuget, it creates a packages\FSharp.Data.1.1.10\lib\net40 directory where it puts FSharp.Data.dll and FSharp.Data.DesignTime.dll . According to Telerik JustDecompile, FSharp.Data.dll is a .NET 4.0 dll, but FSharp.Data.DesignTime.dll is a .NET 4.5 dll even though it resides in the net40 subdirectory. So, is FSharp.Data.DesignTime .NET 4.5 only, or is this a bug? 回答1: Yes, FSharp.Data.DesignTime is .NET 4.5, but

Type inference of functions as arguments

☆樱花仙子☆ 提交于 2019-12-10 14:47:33
问题 I would like to write a function which takes several tupples as arguments and choose theirs ith elements and passes to another function, where i is given as another argument. I've tried sth like this: let function (tup1:'A*'A) (tup2:'B*'B) i = otherFunction (i tup1) (i tup2) function Tup1 Tup2 fst I've got an error, because i was expected to be 'A*'A ->'A not 'B*'B->'B . Is it any way to make this code to work? Thanks in advance. 回答1: You basically want to pass an argument of type ∀'a.'a*'a->

“CompileAssemblyFromSource” in f# powerPack codeDom

大兔子大兔子 提交于 2019-12-10 14:43:40
问题 I am trying to get going a basic program to dynamically compile and run f# code. I am trying to run the following code: open System open System.CodeDom.Compiler open Microsoft.FSharp.Compiler.CodeDom // Our (very simple) code string consisting of just one function: unit -> string let codeString = "module Synthetic.Code\n let syntheticFunction() = \"I've been compiled on the fly!\"" // Assembly path to keep compiled code let synthAssemblyPath = "synthetic.dll" let CompileFSharpCode(codeString,

F# Types and Looping

久未见 提交于 2019-12-10 14:42:51
问题 I am working on an F# tutorial that creates a deck of cards. The types are listed, but I cannot understand how to loop through the types to create the map of the full deck. I expected to do something like Foreach rank in ranks Foreach suit in suits somehow combine the two next suit next rank Is there no way to do this? Below are the types created. I think if I changed them from types to lists they could union, right? So, what's the point of types? type suits= |Spade=1 |Heart=2 |Club=3

Entity Framework and Anonymous Types in F#

删除回忆录丶 提交于 2019-12-10 14:36:59
问题 Trying to get a query with an anonymous type working: let temporaryBookModel = query <@ context.Books |> Seq.filter (fun book -> book.Id = bookId) |> Seq.map(fun item -> (item.Id, item.ParentUser.Id, item.ParentUser.Alias, item.Tagline, item.Title, item.Visible, item.CreatedDate)) |> Seq.head @> And I keep getting: {"Only parameterless constructors and initializers are supported in LINQ to Entities."} Which would make sense if I were mapping the values to a type directly, but anonymous types