f#

Continued “Is there an equivalent of C#'s nameof(..) in F#?”

妖精的绣舞 提交于 2020-12-10 17:00:19
问题 With reference to Is there an equivalent of C#'s nameof(..) in F#? how can the nameof function used or extended for the following case? let nameof (q:Expr<_>) = match q with | Patterns.Let(_, _, DerivedPatterns.Lambdas(_, Patterns.Call(_, mi, _))) -> mi.Name | Patterns.PropertyGet(_, mi, _) -> mi.Name | DerivedPatterns.Lambdas(_, Patterns.Call(_, mi, _)) -> mi.Name | _ -> failwith "Unexpected format" let any<'R> : 'R = failwith "!" let s = _nameof <@ System.Char.IsControl @> //OK type A<'a>()

Continued “Is there an equivalent of C#'s nameof(..) in F#?”

柔情痞子 提交于 2020-12-10 16:56:12
问题 With reference to Is there an equivalent of C#'s nameof(..) in F#? how can the nameof function used or extended for the following case? let nameof (q:Expr<_>) = match q with | Patterns.Let(_, _, DerivedPatterns.Lambdas(_, Patterns.Call(_, mi, _))) -> mi.Name | Patterns.PropertyGet(_, mi, _) -> mi.Name | DerivedPatterns.Lambdas(_, Patterns.Call(_, mi, _)) -> mi.Name | _ -> failwith "Unexpected format" let any<'R> : 'R = failwith "!" let s = _nameof <@ System.Char.IsControl @> //OK type A<'a>()

Deconstruct a C# Tuple

泄露秘密 提交于 2020-12-08 07:07:25
问题 Is it possible to deconstruct a tuple in C#, similar to F#? For example, in F#, I can do this: // in F# let tupleExample = (1234,"ASDF") let (x,y) = tupleExample // x has type int // y has type string Is it possible to do something similar in C#? e.g. // in C# var tupleExample = Tuple.Create(1234,"ASDF"); var (x,y) = tupleExample; // Compile Error. Maybe I can do this if I use an external library, e.g. LINQ??? Or do I have to manually use Item1, Item2? e.g. // in C# var tupleExample = Tuple

How to Generate A Specific Number of Random Indices for Array Element Removal F#

╄→尐↘猪︶ㄣ 提交于 2020-12-07 13:45:47
问题 So sCount is the number of elements in the source array, iCount is the number of elements I want to remove. let indices = Array.init iCount (fun _ -> rng.Next sCount) |> Seq.distinct |> Seq.toArray |> Array.sort The problem with the method above is that I need to specifically remove iCount indices, and this doesn't guarantee that. I've tried stuff like while indices.Count < iCount do let x = rng.Next sCount if not (indices.Contains x) then indices <- indices.Add x And a few other similar

How to Generate A Specific Number of Random Indices for Array Element Removal F#

喜夏-厌秋 提交于 2020-12-07 13:44:47
问题 So sCount is the number of elements in the source array, iCount is the number of elements I want to remove. let indices = Array.init iCount (fun _ -> rng.Next sCount) |> Seq.distinct |> Seq.toArray |> Array.sort The problem with the method above is that I need to specifically remove iCount indices, and this doesn't guarantee that. I've tried stuff like while indices.Count < iCount do let x = rng.Next sCount if not (indices.Contains x) then indices <- indices.Add x And a few other similar

How to Generate A Specific Number of Random Indices for Array Element Removal F#

一世执手 提交于 2020-12-07 13:39:41
问题 So sCount is the number of elements in the source array, iCount is the number of elements I want to remove. let indices = Array.init iCount (fun _ -> rng.Next sCount) |> Seq.distinct |> Seq.toArray |> Array.sort The problem with the method above is that I need to specifically remove iCount indices, and this doesn't guarantee that. I've tried stuff like while indices.Count < iCount do let x = rng.Next sCount if not (indices.Contains x) then indices <- indices.Add x And a few other similar

How to Generate A Specific Number of Random Indices for Array Element Removal F#

删除回忆录丶 提交于 2020-12-07 13:37:28
问题 So sCount is the number of elements in the source array, iCount is the number of elements I want to remove. let indices = Array.init iCount (fun _ -> rng.Next sCount) |> Seq.distinct |> Seq.toArray |> Array.sort The problem with the method above is that I need to specifically remove iCount indices, and this doesn't guarantee that. I've tried stuff like while indices.Count < iCount do let x = rng.Next sCount if not (indices.Contains x) then indices <- indices.Add x And a few other similar

How to Generate A Specific Number of Random Indices for Array Element Removal F#

馋奶兔 提交于 2020-12-07 13:36:39
问题 So sCount is the number of elements in the source array, iCount is the number of elements I want to remove. let indices = Array.init iCount (fun _ -> rng.Next sCount) |> Seq.distinct |> Seq.toArray |> Array.sort The problem with the method above is that I need to specifically remove iCount indices, and this doesn't guarantee that. I've tried stuff like while indices.Count < iCount do let x = rng.Next sCount if not (indices.Contains x) then indices <- indices.Add x And a few other similar

How to Generate A Specific Number of Random Indices for Array Element Removal F#

杀马特。学长 韩版系。学妹 提交于 2020-12-07 13:36:35
问题 So sCount is the number of elements in the source array, iCount is the number of elements I want to remove. let indices = Array.init iCount (fun _ -> rng.Next sCount) |> Seq.distinct |> Seq.toArray |> Array.sort The problem with the method above is that I need to specifically remove iCount indices, and this doesn't guarantee that. I've tried stuff like while indices.Count < iCount do let x = rng.Next sCount if not (indices.Contains x) then indices <- indices.Add x And a few other similar