f#

XML documentation for interface methods and record properties

不羁的心 提交于 2019-12-20 02:26:08
问题 It seems the XML documentation works fine for the most cases, but not always. I wanted to make the Intellisense fully available for the parts that are designed for interoperating with C#. So, here's a small (and maybe a bit contrived) example: ///<summary>Well, it's a summary</summary> type Summary = { ///<summary>Gets a short name</summary> Name : string; ///<summary>Gets whether the action was successful or not</summary> IsSuccessful : bool; } ///<summary>Represents path filtering action<

Finding the difference between two arrays in FSharp

[亡魂溺海] 提交于 2019-12-20 02:16:26
问题 I have two arrays where I want to find the elements from the second array that are not in the first array. I wrote the following code: let array0 = [|"A";"B";"C"|] let array1 = [|"B";"D";"E"|] let inZero letter = array0 |> Array.tryFind(fun l -> if l = letter then true else false) array1|> Array.filter(fun l -> inZero(l).IsSome) But I am wondering if there is something that is more idiomatic to FSharp. Thanks in advance 回答1: If you do not care about duplicates, then you could write this using

How does non idiomatic global operator overloading work?

可紊 提交于 2019-12-20 02:11:00
问题 I want to understand the code from this answer type Mult = Mult with static member inline ($) (Mult, v1: 'a list) = fun (v2: 'b list) -> v1 |> List.collect (fun x -> v2 |> List.map (fun y -> (x, y))) : list<'a * 'b> static member inline ($) (Mult, v1:'a ) = fun (v2:'a) -> v1 * v2 :'a let inline (*) v1 v2 = (Mult $ v1) v2 F# can resolve overloaded members. (Because it doesn't support currying of members). So, I supposed, it should work for methods as well But it doesn't: type Mult = Mult with

How does non idiomatic global operator overloading work?

半世苍凉 提交于 2019-12-20 02:09:21
问题 I want to understand the code from this answer type Mult = Mult with static member inline ($) (Mult, v1: 'a list) = fun (v2: 'b list) -> v1 |> List.collect (fun x -> v2 |> List.map (fun y -> (x, y))) : list<'a * 'b> static member inline ($) (Mult, v1:'a ) = fun (v2:'a) -> v1 * v2 :'a let inline (*) v1 v2 = (Mult $ v1) v2 F# can resolve overloaded members. (Because it doesn't support currying of members). So, I supposed, it should work for methods as well But it doesn't: type Mult = Mult with

Xamarin android app throws ResourceNotFoundException

喜夏-厌秋 提交于 2019-12-20 02:08:21
问题 Since 1 week I discovered Xamarin framework, and my job is to make Android app work. iOS app has been already launched before. I had to deal first with some NuGet Packages dependencies, but now the only exception I get is : 06-26 15:01:40.719 E/mono-rt (20038): [ERROR] FATAL UNHANDLED EXCEPTION: Android.Content.Res.Resources+NotFoundException: Resource ID #0x0 06-26 15:01:40.719 E/mono-rt (20038): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder

F# Excel Range.Sort Fails or Rearranges Columns

允我心安 提交于 2019-12-20 01:39:57
问题 I have two cases. The preliminary code: open Microsoft.Office.Interop.Excel let xl = ApplicationClass() xl.Workbooks.OpenText(fileName...) let wb = xl.Workbooks.Item(1) let ws = wb.ActiveSheet :?> Worksheet let rows = string ws.UsedRange.Rows.Count First, I try the following to sort: ws.Sort.SortFields.Clear() ws.Sort.SortFields.Add(xl.Range("A8:A" + rows), XlSortOn.xlSortOnValues, XlSortOrder.xlAscending, XlSortDataOption.xlSortNormal) |> ignore ws.Sort.SortFields.Add(xl.Range("H8:H" + rows)

Why is generic type in some expressions is matched as obj in F# pattern matching?

与世无争的帅哥 提交于 2019-12-20 01:38:51
问题 I have the following code: type Message<'a> = | Message of 'a let handleMessage message = match box message with | :? Message<_> -> printfn "Message" | _ -> printfn "Not message" let handleMessageEx message = match box message with | :? Message<int> -> printfn "Message" | _ -> printfn "Not message" handleMessage <| Message 1 handleMessage <| Message (1 :> obj) handleMessageEx <| Message 1 The output in F# Interactive is the following: Not message Message Message Why does the first statement

F# discriminated union syntax clarification

半城伤御伤魂 提交于 2019-12-20 01:13:52
问题 I'm reading Expert F# 4.0 and at some point (p.93) the following syntax is introduced for list : type 'T list = | ([]) | (::) of 'T * 'T list Although I understand conceptually what's going on here, I do not understand the syntax. Apparently you can put [] or :: between parentheses and they mean something special. Other symbols aren't allowed, for example (++) or (||) . So what's going on here? And another thing is the 'operator' nature of (::) . Suppose I have the following (weird) type:

F# how to append/join array2D and combine 1D arrays to array2D

我与影子孤独终老i 提交于 2019-12-19 17:57:26
问题 in F#, array.append can join two arrays; is there a way to append 2 array2D objects into one or column-wise join several 1-D arrays into one array2D object? 回答1: The array2D function will turn any seq<#seq<'T>> into a 'T [,] so it should work for turning a bunch of 1D arrays into a 2D array. let arr1 = [| 1; 2; 3 |] let arr2 = [| 4; 5; 6 |] let combined = array2D [| arr1; arr2 |] 回答2: As far as I can see, there is no F# library function that would turn several 1D arrays into a single 2D array

Is there a way to have warnings for shadowing values in F# in Visual Studio?

喜欢而已 提交于 2019-12-19 17:32:35
问题 To me shadowing of existing values like described in: Shadowing and Nested function immutable in F# f# duplicate definition FSharp for fun and profit comment seems to be going against the notion of immutability and type safety that makes F# so strong. Shadowing in F# works different than in C#. It just took me quite some time to find out that a bug in my code was due to unintentional shadowing of a name within the same scope. Is there a way to have compiler warnings for shadowing values in VS