f#

ServiceModel and f#

早过忘川 提交于 2019-12-11 09:47:03
问题 I am just starting with f# so the question may seem easy for some of you. so, I am trying to use SyndicationFeed which is located in System.ServiceModel.Syndication namespace. I added following references: System.ServiceModel and System.ServiceModel.Web to the project. The result is that it builds successfully, but when I switch to "F# interactive" window I got an error which reads "error FS0039: The namespace 'ServiceModel' is not defined". I goggled that I should also add reference to

Chaining REST calls in a pipeline while managing errors

ぐ巨炮叔叔 提交于 2019-12-11 09:43:54
问题 Coming from nodejs where I could chain asynchronous events using Promises and then operator I'm trying to explore how things are done in idiomatic F#. The calls I'm trying to chain are HTTP rest calls on some entity from creation to update to uploading images to publishing. Function composition says the output of one function should match the input of the second one to be composed and that common input and output in my case will be string , i.e. JSON serialized string as input and output of

F# match pattern for Expr<int>

点点圈 提交于 2019-12-11 09:40:08
问题 I try to find the correct pattern to match and run an Expr<int> using the below code: open System.Linq open Microsoft.FSharp.Quotations open Microsoft.FSharp.Quotations.Patterns let runSelectQuery (q:Expr<IQueryable<'T>>) = match q with | Application(Lambda(builder, Call(Some builder2, miRun, [Quote body])), queryObj) -> query.Run(Expr.Cast<Microsoft.FSharp.Linq.QuerySource<'T, IQueryable>>(body)) | _ -> failwith "Cannot run this query %s" (q.ToString()) let runCountQuery (q:Expr<int>) =

Why does value restriction happen with MergeSort function?

落爺英雄遲暮 提交于 2019-12-11 09:32:07
问题 I have a very simple MergeSort implementation on List. /// Divide the list into (almost) equal halves let rec split = function | [] -> [], [] | [x] -> [x], [] | x1::x2::xs -> let xs1, xs2 = split xs x1::xs1, x2::xs2 /// Merge two sorted lists let rec merge xs ys = match xs, ys with | [], _ -> ys | _, [] -> xs | x::xs', y::ys' when x <= y -> x::merge xs' ys | _, y::ys' -> y::merge xs ys' let rec mergeSort = function | [] -> [] | xs -> let xs1, xs2 = split xs merge (mergeSort xs1) (mergeSort

C# WPF project with reference to F# ViewModel

。_饼干妹妹 提交于 2019-12-11 09:29:37
问题 I have project named FSharpProject in whick there is code like this: module FSharpProject.ViewModel type A = member x.a = 1 In other project(typical wpf application writing in C#) which have reference to FSharpProject I have xaml file like this: <UserControl x:Class="CSharpProjectView" x:Name="Root" xmlns:local="clr-namespace:CSharpProjectView" xmlns:data="clr-namespace:FSharpProject.ViewModel;assembly=FSharpProject" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=

Mono compiler // Terminal emulator issue

浪尽此生 提交于 2019-12-11 09:14:09
问题 I get this error when I try to compile csharp or fsharp files. This happens when using gnome terminal or jetbrain rider. It works fine in tty or termials like xterm and urxvt. Also I am able to compile c, c++ and go code. Btw, I am using Arch/Antergos and got this issue yesterday. Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.Console' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.ConsoleDriver' threw

Deedle Frame.mapRows how to properly use it and how to construct objectseries properly

℡╲_俬逩灬. 提交于 2019-12-11 09:11:55
问题 I also noticed something strange about Deedle mapRows function i cant explain: let col1 = Series.ofObservations[1=>10.0;2=>System.Double.NaN;3=>System.Double.NaN;4=>10.0;5=>System.Double.NaN;6=>10.0; ] let col2 = Series.ofObservations[1=>9.0;2=>5.5;3=>System.Double.NaN;4=>9.0;5=>System.Double.NaN;6=>9.0; ] let f1 = Frame.ofColumns [ "c1" => col1; "c2" => col2 ] let f2 = f1 |> Frame.mapRows (fun k r -> r) |> Frame.ofRows let f3 = f1 |> Frame.mapRows (fun k r -> let x = r.Get("c1"); let y = r

How do I pass an array from .Net to C?

六月ゝ 毕业季﹏ 提交于 2019-12-11 09:02:45
问题 I am trying to make use of an open source library, written in C, by wrapping it and exposing it to .Net. I am not, by any stretch, a C expert. So far, I have managed to call the demo code, written in C, from F#. I managed to get this far by following this guide then filling in the blanks. I have adapted the C code to expect an int passed to it, so I can at least take in a scalar value from F# into C. No return value though. But working with arrays is much trickier. My C code is extern "C" { _

f# match expression - “rule will never be matched”

一世执手 提交于 2019-12-11 08:57:31
问题 I'm trying to learn F# and I've come to a point where I don't understand what I am doing wrong. I wrote the following code: let p = 0.2::0.2::0.2::0.2::0.2::[] let world = "g"::"r"::"r"::"g"::"g"::[] let measurements = "r"::"g"::[] let pHit = 0.6 let pMiss = 0.2 let rec sense world probs measurement = match world, probs with | measurement::row, p::rop -> (p*pHit)::sense row rop measurement | _::row, p::rop -> (p*pMiss)::sense row rop measurement | [],_ -> [] | _,[] -> [] The problem I got is

Generic extraction from a constructor

别说谁变了你拦得住时间么 提交于 2019-12-11 08:48:49
问题 In F# and OCaml I wind up writing a lot of code like type C = Blah of Whatever let d = Blah (createWhatever ()) // so d is type C ... let x = match d with | Blah b -> b What I'd like is this ... let x = peel d Where peel would work for any constructor/discriminator. Surely I'm not the only one annoyed by this. edit: Good answers, but I don't have the rep to vote on them. How about this situation? member self.Length = match self with | L lab -> lab.Length 回答1: It is not possible to do that