f#

How to fold over a discriminated union

六眼飞鱼酱① 提交于 2019-12-07 23:51:28
问题 I'm attempting to implement a fold over a discriminated union. The DU is called Expr, and represents a program expression, and is often recursive. I'm attempting to write a fold that accumulates the result of an operation over the Exprs recursively. Below is my attempt to write the fold. let rec foldProceduralExpr (folder : 's -> Expr list -> 's) (state : 's) (expr : Expr) : 's = let children = match expr with | Series s -> s.SerExprs | Lambda l -> [l.LamBody; l.LamPre; l.LamPost] | Attempt a

Shorthand for calling a method on an object in F#

混江龙づ霸主 提交于 2019-12-07 22:22:16
问题 Is there a way to "generate" functions like this one: fun x -> x.ToString I would like to be able to turn an instance method into a static method which takes "this" as a parameter, like so: items |> Seq.filter my_predicate |> Seq.map Object.ToString 回答1: this has been discussed several times on the F# hub. See for example instance methods as functions. This is quite tricky problem, so there are no plans to have something like this in the first version of F# as far as I know, but it would be

Map to Deedle Frame

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 22:15:03
问题 I am learning F#. I am trying to convert a Map<string, seq<DateTime * float>> to a Deedle dataframe (http://bluemountaincapital.github.io/Deedle/tutorial.html#creating). I have prapared the following code: let folderFnct (aFrame:Frame) colName datesAndValues = let newSerie = Series(Seq.map (fun x -> fst x) datesAndValues, Seq.map (fun y -> snd y) datesAndValues) let newFrame = aFrame.Join([colName], [newSerie], kind=JoinKind.Inner) newFrame let mapToDeedleFrame myMap frame = Map.fold ( fun s

List processing with intermediate state

▼魔方 西西 提交于 2019-12-07 20:19:29
问题 I am processing a list of strings, you can think of them as lines of a book. When a line is empty it must be discarded. When it is a title, it is "saved" as the current title. Every "normal" line must generate an object with its text and the current title. In the end you have a list of lines, each with its corresponding title. Ex.: - Chapter 1 Lorem ipsum dolor sit amet consectetur adipisicing elit - Chapter 2 sed do eiusmod tempor incididunt u First line is a title, second line must be

Find string permutation including the single character using C# or F#

有些话、适合烂在心里 提交于 2019-12-07 18:48:18
问题 I would like to generate a list of all possible permutations of a string containing a variable list of characters. For example if I have the string "ABC", I would like to have a list that contains all the possible variations, like: A, B, C, AB, BC. Thank you. 回答1: Here's a LINQ version: Func<string, IEnumerable<string>> perm = t => { Func<string, string, IEnumerable<string>> perm2 = null; perm2 = (t0, t1s) => from n in Enumerable.Range(0, t1s.Length) let c = t1s.Substring(n, 1) let x = t1s

Binding events to buttons in an ItemsControl

不打扰是莪最后的温柔 提交于 2019-12-07 18:14:33
问题 I have a windows phone 7 app with some xaml that looks like: <Grid x:Name="ContentGrid" Grid.Row="1"> <ItemsControl x:Name="MyView" ItemTemplate="{StaticResource MyInner}"/> </Grid> The item template here looks like: <DataTemplate x:Key="MyInner"> <ItemsControl ItemsSource="{Binding}" ItemTemplate="{StaticResource MyInner_Item}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DataTemplate

how to XML-Serialize array of an array in FSharp

▼魔方 西西 提交于 2019-12-07 17:47:41
问题 here's what I'm looking for: <reports> <parameters> <parameter name="srid" type="java.lang.Integer">16533</parameter> <parameter name="pmid" type="java.lang.Integer">17018</parameter> <parameter name="Start" type="java.text.SimpleDateFormat">1/1/2011 12:00:00 AM</parameter> <parameter name="End" type="java.text.SimpleDateFormat">1/31/2011 12:00:00 AM</parameter> </parameters> <parameters> <parameter name="srid" type="java.lang.Integer">16099</parameter> <parameter name="pmid" type="java.lang

How to create a Union type in F# that is a value type?

£可爱£侵袭症+ 提交于 2019-12-07 17:31:17
问题 Normal F# Discriminated Unions are reference types. How can I create a simple (non-recursive and with only value-type fields) union type in F# that is a value type? Based on some internet searching my current (non-working) attempt looks as follows: [<StructLayout(LayoutKind.Explicit)>] type Float = [<DefaultValue>] [<FieldOffset 0>] val mutable Val1 : float [<DefaultValue>] [<FieldOffset 0>] val mutable Int1 : int new (a:float) = {Val1 = a} The following blog post appears to show what is

Type provider for MySql

淺唱寂寞╮ 提交于 2019-12-07 17:23:15
问题 I've been searching for an example on how to connect to a MySql database and use F# type providers but I could not find anything online. Can anyone give me a clue? What - if any - extra packages do I need? Do I use SqlDataConnection or SqlEntityConnection . Excuse my ignorance but I'm totally lost. Any and all help is appreciated. I love the idea of type providers and have a fair amount of experience with functional programing but it's the setup around this that gets me. 回答1: I don't think

Why doesn't F# support Edit and Continue? [closed]

穿精又带淫゛_ 提交于 2019-12-07 16:38:20
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Visual Studio's Edit and Continue and other IDE's equivalent operations are very effective for experimentation in interactive applications, since you don't have to restart the app to see the effects of the code change (most of the time). If Visual Studio already supports this