f#-3.0

How to generate C#-friendly, .Net 4.0 compatible types using F# 3.0 type providers

无人久伴 提交于 2019-12-05 17:55:29
问题 I want to generate "strong" types based on "weakly" typed data sources, using the F# 3.0 type provider mechanism. The generated types must be accessible from C# clients in an environment where only .Net 4.0 is installed, but not .Net 4.5. If .Net 4.0 compatibility is not possible, we cannot use type providers in our current large-scale ERP project. So far, I have succeeded in creating MyGeneratedTypes.dll by following the tutorial on msdn (section "Providing Generated Types"), using the

FSharp.Core for Windows Phone 7.1 and F# 3.0

試著忘記壹切 提交于 2019-12-05 11:04:08
问题 The F# 2.0 distribution had a version of FSharp.Core compiled for WindowsPhone 7.1/Silverlight 4, but F# 3.0 doesn't, and the portable version only supports Silverlight 5 or Windows Phone 8. Has anyone been able to compile a version of FSharp.Core for F# 3.0 targeting Silverlight 4 or Windows Phone 7.1 from source? What are the defines required? Edit: On the fsharp compiler github repo, there's a target named portable-net4+sl4+wp71+win8, but in reality that's portable class library Profile47,

How to obtain F# powerpack for F# 3.0

青春壹個敷衍的年華 提交于 2019-12-04 05:56:14
I'm using VS11 Beta on Win 8 Consumer Preview. After install VS11 Beta I have F# 3.0 SDK installed. But I'm not able to find a compatible FSharp.PowerPack.dll as CodePlex only provides PowerPack for F# 2.0. Any idea how to deal with this? Brian You can compile the PowerPack sources on your own (against F# 3.0), to make your own copy of the library. Alternatively, I think a binding redirect in your final foo.exe.config, along the lines of https://stackoverflow.com/a/9648673/19299 but redirecting 2.0.0.0 (that PowerPack uses) to 4.3.0.0 (in VS11 SDK) will also work. In addition to what Brian

Defining new keywords in F#'s computation expression

眉间皱痕 提交于 2019-12-03 15:08:09
问题 The F# 3.0 beta contains a query {} computation expression with tons of new keywords. How can I define my own keywords in a computation builder? 回答1: In F# 3.0, you can use CustomOperationAttribute for this purpose. The new attribute is not very well-documented, the only examples I find are this great answer by @Tomas and this interesting blog post. 来源: https://stackoverflow.com/questions/9565986/defining-new-keywords-in-fs-computation-expression

Bitmap image manipulation

会有一股神秘感。 提交于 2019-12-01 20:20:42
I want to replace GetPixel and SetPixel using LockBits method, so I came across this F# lazy pixels reading open System.Drawing open System.Drawing.Imaging let pixels (image:Bitmap) = let Width = image.Width let Height = image.Height let rect = new Rectangle(0,0,Width,Height) // Lock the image for access let data = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat) // Copy the data let ptr = data.Scan0 let stride = data.Stride let bytes = stride * data.Height let values : byte[] = Array.zeroCreate bytes System.Runtime.InteropServices.Marshal.Copy(ptr,values,0,bytes) // Unlock the

Active pattern broken in F# 3.0

廉价感情. 提交于 2019-12-01 17:09:53
This active pattern compiles with F# 2.0: let (|Value|_|) value = // 'a -> 'T option match box value with | :? 'T as x -> Some x | _ -> None but, in F# 3.0, emits the error: Active pattern '|Value|_|' has a result type containing type variables that are not determined by the input. The common cause is a [sic] when a result case is not mentioned, e.g. 'let (|A|B|) (x:int) = A x'. This can be fixed with a type constraint, e.g. 'let (|A|B|) (x:int) : Choice = A x' I tried: let (|Value|_|) value : 'T option = ... and: let (|Value|_|) (value: 'U) = ... How can it be fixed? Environments: Visual

F# Func type inference difference between Seq and PSeq ToDictionary

只谈情不闲聊 提交于 2019-12-01 16:38:54
Given a trivial sequence of tuples, and a parallel one using F# PowerPack's PSeq: let a = Seq.singleton (1,"a") --> val a: seq<int * string> let b = a |> PSeq.map id --> val b: pseq<int * string> Now I'd like to create a .Net BCL dictionary from them: let bd = b.ToDictionary(fst, snd, HashIdentity.Structural) let ad = a.ToDictionary(fst, snd, HashIdentity.Structural) let ad2 = a.ToDictionary(fst, snd) let ad3 = a.ToDictionary((fun (x,y) -> x), (fun (x,y) -> y), HashIdentity.Structural) While let bd works, let ad does not compile as it fails to infer types and convert to BCL's Func correctly.

F# Func type inference difference between Seq and PSeq ToDictionary

心已入冬 提交于 2019-12-01 15:27:41
问题 Given a trivial sequence of tuples, and a parallel one using F# PowerPack's PSeq: let a = Seq.singleton (1,"a") --> val a: seq<int * string> let b = a |> PSeq.map id --> val b: pseq<int * string> Now I'd like to create a .Net BCL dictionary from them: let bd = b.ToDictionary(fst, snd, HashIdentity.Structural) let ad = a.ToDictionary(fst, snd, HashIdentity.Structural) let ad2 = a.ToDictionary(fst, snd) let ad3 = a.ToDictionary((fun (x,y) -> x), (fun (x,y) -> y), HashIdentity.Structural) While

F# How Async<'T> cancellation works?

我怕爱的太早我们不能终老 提交于 2019-12-01 03:16:09
I was pretty comfortable with how async cancellations where done in C# with the TPL, but I am a little bit confused in F#. Apparently by calling Async.CancelDefaultToken() is enough to cancel outgoing Async<'T> operations. But they are not cancelled as I expected, they just... vanishes... I cannot detect properly the cancellation and tear down the stack properly. For example, I have this code that depends on a C# library that uses TPL: type WebSocketListener with member x.AsyncAcceptWebSocket = async { let! client = Async.AwaitTask <| x.AcceptWebSocketAsync Async.DefaultCancellationToken if

Is F# 3.0 available on Visual Studio 2010 professional? [closed]

荒凉一梦 提交于 2019-12-01 02:49:44
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I would love to try f# 3.0 but I only have visual studio 2010 professional. I know F# 3.0 comes installed with visual studio 2012 out of the box, but I'm not in a position where I can upgrade to vs2012 yet. A recent msdn post by Don Syme hints that it can be used with visual studio 2010, but there doesn't seem