f#

F# : A recursive value that can reference itself

纵然是瞬间 提交于 2019-12-31 00:45:14
问题 I have a record : type node = { content : string; parent : node option; branch : string option; children : seq<node> option; } Which I want to instantiate this way : let rec treeHead = { content = "Value" parent = None; branch = None; children = tree (Some(treeHead)) rows; }; Where let rec tree (parent:node option) (rows:seq<CsvRow>) :seq<node> option Is a a recursive function that gets the children of a node (to construct a tree). So as you can see the object treeHead needs to call itself

C# to F# Convert public partial class Device : MarshalByRefObject

∥☆過路亽.° 提交于 2019-12-30 21:59:46
问题 public partial class Device : MarshalByRefObject { internal bool FindTagName(string name, OneTag tag) { foreach (FuncSect fs in listFuncSect) { foreach (OneTag ot in fs.listTags) { if (ot != tag && ot.Name == name) return true; } } return false; } still have no idea how to convert this "partial" and "internal" to F# thank you 回答1: As leppie says, there's no direct support for partial , although you could achieve a similar effect with intrinsic type extensions. F# does support internal methods

C# to F# Convert public partial class Device : MarshalByRefObject

╄→гoц情女王★ 提交于 2019-12-30 21:59:45
问题 public partial class Device : MarshalByRefObject { internal bool FindTagName(string name, OneTag tag) { foreach (FuncSect fs in listFuncSect) { foreach (OneTag ot in fs.listTags) { if (ot != tag && ot.Name == name) return true; } } return false; } still have no idea how to convert this "partial" and "internal" to F# thank you 回答1: As leppie says, there's no direct support for partial , although you could achieve a similar effect with intrinsic type extensions. F# does support internal methods

How to get generic type definition for CRTP type

瘦欲@ 提交于 2019-12-30 18:54:13
问题 Given the following CRTP type in C#: public abstract class DataProviderBase<TProvider> where TProvider : DataProviderBase<TProvider> { } How would I get its generic type definition in F#? let typeDef = typedefof<DataProviderBase<_>> yields the error: Type constraint mismatch when applying the default type 'DataProviderBase<'a>' for a type inference variable. The resulting type would be infinite when unifying ''a' and 'DataProviderBase<'a>' Consider adding further type constraints In C#, it

Extracting Leaf paths from n-ary tree in F#

爷,独闯天下 提交于 2019-12-30 18:51:33
问题 Inspired by this question, I wanted to try my hand at the latest ponder this challenge, using F# My approach is probably completely off course, but in the course of solving this problem, I'm trying to get a list of all the permutations of the digits 0-9. I'm looking at solving it using a n-ary tree like so: type Node = | Branch of (int * Node list) | Leaf of int I'm quite pleased with myself, because I've managed to work out how to generate the tree that I want. My problem now is that I can't

Why Frame.X static methods from Deedle are generating warnings in VS 2017?

廉价感情. 提交于 2019-12-30 17:45:39
问题 I downloaded the new VS 2017 yesterday and it is working fine, except that I am getting this warning on every line where I call the static method Frame.ReadCsv from the Deedle package: FS10001 This method is not intended for use from F# Calls to other static methods Frame.X do not generate the same warning. Example - this line of code generates the warning: let msft = Frame.ReadCsv(Config.tsDir + "MSFT.csv", hasHeaders=true, inferTypes=true) Intellisense recognizes the method and provides the

Active pattern broken in F# 3.0

谁都会走 提交于 2019-12-30 17:38:43
问题 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

FirstOrDefault In F#

北战南征 提交于 2019-12-30 17:26:50
问题 How to write FirstOrDefault Linq Query in F#? Can I use linq to sql in F# in totally? 回答1: Note that a more idiomatic approach within F# would probably be to use something along the lines of Seq.tryFind rather than to use the LINQ operators, although it's not a drop in replacement since it returns an option value. 回答2: Because the Seq module already has a head function of type seq<'a> -> 'a , I would define a function tryHead with signature seq<'a> -> option<'a> : module Seq = let tryHead (ls

FirstOrDefault In F#

醉酒当歌 提交于 2019-12-30 17:26:21
问题 How to write FirstOrDefault Linq Query in F#? Can I use linq to sql in F# in totally? 回答1: Note that a more idiomatic approach within F# would probably be to use something along the lines of Seq.tryFind rather than to use the LINQ operators, although it's not a drop in replacement since it returns an option value. 回答2: Because the Seq module already has a head function of type seq<'a> -> 'a , I would define a function tryHead with signature seq<'a> -> option<'a> : module Seq = let tryHead (ls

How To Apply a Function to an Array of float Arrays?

点点圈 提交于 2019-12-30 11:08:31
问题 Let's suppose I have n arrays, where n is a variable (some number greater than 2, usually less than 10). Each array has k elements. I also have an array of length n that contains a set of weights that dictate how I would like to linearly combine all the arrays. I am trying to create a high performance higher order function to combine these arrays in F#. How can I do this, so that I get a function that takes an array of arrays (arrs is a sample), a weights array (weights), and then computed a