f#

Type inference on ToString() vs string operator

☆樱花仙子☆ 提交于 2020-01-03 20:31:29
问题 Note: This question is somewhat related to my previous one, but it actually touches the issue from different perspective Consider following snippet: let toStr a = a.ToString() let strOp a = string a let intToStr = 5 |> toStr let floatToStr = 5.0 |> toStr let intStrOp = 5 |> strOp let floatStrOp = 5.0 |> strOp //type inference error While the strOp function uses what appears to be more elegant solution, and is able to convert a unit value to string as well, it seems not to be truly generic

Solving circular references for a project that uses both C# and F#

自闭症网瘾萝莉.ら 提交于 2020-01-03 19:40:38
问题 So here's my situation. I have a class library in C#. It exposes some types like Rectangle . It also exposes some methods for doing algorithmic computation. It seemed like a good idea to write those algorithmic bits in F#. So I added another F# library project to the solution. Now here's the issue. In order for the F# project to do algorithmic computations it needs to know about the Rectangle from the C# project. And in order for the C# project to be able to use the F# functions it needs to

Solving circular references for a project that uses both C# and F#

巧了我就是萌 提交于 2020-01-03 19:40:29
问题 So here's my situation. I have a class library in C#. It exposes some types like Rectangle . It also exposes some methods for doing algorithmic computation. It seemed like a good idea to write those algorithmic bits in F#. So I added another F# library project to the solution. Now here's the issue. In order for the F# project to do algorithmic computations it needs to know about the Rectangle from the C# project. And in order for the C# project to be able to use the F# functions it needs to

What happened to Microsoft.FSharp.Math.Matrix?

房东的猫 提交于 2020-01-03 19:15:14
问题 Kind of strange how this class type has dropped of the F# released with VS2010 Does anyone know where it has gone? or where it is now? 回答1: It is in the F# powerpack, which is used by the F# team for "unstable" code that will get released and updated more often than the main release of F# and libraries. (Note that the code is still high-quality code, you should ignore most of the connotations that "unstable" has in this case). It's just a way for the F# team to get more experimental code out

F# Pattern-matching by type

时间秒杀一切 提交于 2020-01-03 18:57:49
问题 How pattern-matching by type of argument works in F#? For example I'm trying to write simple program which would calculate square root if number provided or return it's argument otherwise. open System let my_sqrt x = match x with | :? float as f -> sqrt f | _ -> x printfn "Enter x" let x = Console.ReadLine() printfn "For x = %A result is %A" x (my_sqrt x) Console.ReadLine() I get this error: error FS0008: This runtime coercion or type test from type 'a to float involves an indeterminate type

Accessing dynamic property in F#

与世无争的帅哥 提交于 2020-01-03 18:45:27
问题 I was trying to access dynamic property in Nancy. In Nancy if pass parameter in query it comes as dynamic property. How can I access that. There are many discussion / question about this but every where, first it is of creating dynamic and then consuming it. How can I consume what is already created? Here are two code snippet public class ParameterModule : NancyModule { public ParameterModule():base("/{about}") { this.Get["/"] = (parameters) => "Hello About" + parameters.about; } } and for F#

How can I define this lazy (infinite?) data structure in F#

本秂侑毒 提交于 2020-01-03 18:18:15
问题 I am having a problem defining the following simple text cursor which is represented by a tuple where the first element is a current character and the second one if a function that gets the next one or crashes. let rec nextAt index text = if index < String.length text then (text.[index], (fun() -> nextAt (index + 1) text)) else failwith "End of string." I am getting Error 1 Type mismatch. Expecting a char * (unit -> 'a) but given a 'a The resulting type would be infinite when unifying ''a'

Count unique in a Deedle Series

て烟熏妆下的殇ゞ 提交于 2020-01-03 17:29:11
问题 I want to have an overview of a Series in my dataframe, something like pandas' unique values counting. I don't know if there's a built-in function for that. So far i've done a function to just get the numbers of different features. I could manage to do the job, my question is only about a built-in function. let unique (s:Deedle.Series<'a,'a>) = s.Values |>Seq.distinct |>Seq.length I want a result like : [("value1",5);("value2",8)] 回答1: You can use the groupInto function - this lets you group

Platform Invoke F# callback functions

╄→尐↘猪︶ㄣ 提交于 2020-01-03 17:25:44
问题 I am using F# on a Raspberry Pi 2 (ARM 7 & thus mono). I am currently trying to use the WiringPi library, written in C. I have successfully managed to use some of the functions using P/Invoke. Now I am trying to use interrupts (see http://wiringpi.com/reference/priority-interrupts-and-threads/) but I am stumped by this function with the following C signature int wiringPiISR (int pin, int edgeType, void (*function)(void)); Which has been translated (see https://github.com/danriches/WiringPi

Seq.unfold explanation in F#

*爱你&永不变心* 提交于 2020-01-03 17:15:35
问题 I am trying to create a sequence lazily by using F#. The sequence is defined as follows: The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangle numbers are: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Here is what I have so far but it dosn't seem to work: let tri_seq = 1.0 |> Seq.unfold (fun x -> match x with | _ -> Some (x, 0.5*x*(x + 1.0))) Thank you very much who can help me figure out how unfold works. Thanks Edit: I marked the first answer as