f#

Twitter stream api with agents in F#

孤者浪人 提交于 2019-12-10 11:25:02
问题 From Don Syme blog (http://blogs.msdn.com/b/dsyme/archive/2010/01/10/async-and-parallel-design-patterns-in-f-reporting-progress-with-events-plus-twitter-sample.aspx) I tried to implement a twitter stream listener. My goal is to follow the guidance of the twitter api documentation which says "that tweets should often be saved or queued before processing when building a high-reliability system". So my code needs to have two components: A queue that piles up and processes each status/tweet json

Plotting data of deedle data frame with Xplot plotly

血红的双手。 提交于 2019-12-10 11:16:47
问题 I have a Deedle data frame with DateTime values as key and two columns with data. Now I want to plot the data of column 1 with a Scatter chart from Plotly. I am using FSLab and there is XPlot.Plotly 1.3.1 included. But I can't use Plotly: open XPlot.Plotly.Graph open XPlot.Plotly open XPlot.Plotly.HTML let dataFrame = ... Scatter( x = dataFrame.ColumnKeys, y = dataFrame.GetColumn("col1") ) |> Chart.Plot |> Chart.Show I'm getting this error: "The field, constructor or member 'Plot' is not

Error using bool.Parse on null/empty values

隐身守侯 提交于 2019-12-10 11:01:42
问题 I have an expression using pipe operator that converts the value to string and then to bool, however sometimes the original value can be null. How can I use the pattern matching or something else to assume false when the value is null? type kv = Dictionary<string, obj> let allDayEvent (d: kv) = d.["fAllDayEvent"] |> string |> bool.Parse 回答1: There's quite a few places where you can safeguard via pattern matching: dictionary lookup, casting, parsing. Here's an example with all of those: let

Using F# Datatypes in C#

被刻印的时光 ゝ 提交于 2019-12-10 10:53:27
问题 More particularly, I really want an immutable/shared linked list, and I think having immutable maps and sets would be nice too. As long as I don't have to worry about the core implementation, I can easily add extension methods/subclass/wrap it to provide a reasonably slick external interface for myself to use. Is there any reason I shouldn't do this? Performance, incompatibility, etc.? 回答1: The types in the F# library (such as Set , Map and list ) were not designed to be used from C#, so I

F# and negative match

眉间皱痕 提交于 2019-12-10 10:48:35
问题 I have a discriminated type: type Item = | Normal of string * float32 | Special1 of Item | Special2 of Item And I have a function using this type: let rec calcItem (i: Item ) = match i with | Normal(_, p) -> p | Special1(g) | Special2(g) -> (calcItem g) + 1 In my case, the Special_ n types will be defined in the same form. So I am wondering if it is possible to use wildcard pattern to match all these types. The _ match does not work, because it does not accept arguments. 回答1: Similar to this

Compile error for Kleisli composition

邮差的信 提交于 2019-12-10 10:25:13
问题 I have a validation module copied from Railway oriented programming that performs error handling in my application: type ErrorMessage = ErrorMessage of string type ValidationResult<'T> = | Success of 'T | Error of ErrorMessage module ValidationResult = let doubleMap successHandler errorHandler = function | Success x -> successHandler x | Error e -> errorHandler e let bind f = function | Success x -> f x | Error e -> Error e let (>=>) f g = f >> bind g I was testing the Kleisli composition by

in F# on MAC OSX and Ubuntu I get an error running FSI in 4.0

寵の児 提交于 2019-12-10 10:19:59
问题 I need System.Numerics in F# EDIT I think the question is can fsi run with the 4.0 runtime and if so how do I configure it I run "mono /bin/Fsi" in the Fsharp 4.0 dir I get the following error in both OSX 10.6.4 and Ubuntu 10.1. I am sure I am missing a path or something Please note the paths are different on the MAC but I got the same error error FS0078: Unable to find the file 'System.Numerics.dll' in any of /opt/mono-2.8/lib/mono/2.0 /home/gary/Downloads/FSharp-2.0.0.0/v4.0/bin /home/gary

F# limitations of discriminated unions

狂风中的少年 提交于 2019-12-10 10:16:30
问题 I am trying to port a small compiler from C# to F# to take advantage of features like pattern matching and discriminated unions. Currently, I am modeling the AST using a pattern based on System.Linq.Expressions: A an abstract base "Expression" class, derived classes for each expression type, and a NodeType enum allowing for switching on expressions without lots of casting. I had hoped to greatly reduce this using an F# discriminated union, but I've run into several seeming limitations: Forced

F# XML Type Provider Common Elements

偶尔善良 提交于 2019-12-10 10:15:59
问题 XSD specifications for XML files can share common elements. If I have several XML files that share a common element, is there a way to extract the common element without repeating the code for each XML file type? For example: There are a number of XML files defined via XSD, with a common description element, but different content structures elsewhere. The description has subelements with things like author, date, etc. When I create a type provider for each of the XML files, the types are

F# type provider use case

风流意气都作罢 提交于 2019-12-10 10:08:15
问题 I have a bit of hard time to get a grip on type providers. I would like to get some feedback on the usefulness of type provider approach for following use case. Quite unfortunately our telemetry API returns objects as List<Dictionary<string, object>> . Dictionary has strings for keys (meaning column names) and value can be any object (though, usually this is some value type in System namespace). Also, there is an method that returns Dictionary<string, Type> collection that represents the