f#

FSharp.Data 'System.MissingMethodException' when calling Freebase Provider from C#

落花浮王杯 提交于 2019-12-20 03:53:22
问题 Hi I have this piece of code on F#, if I test it from the F# Interactive Editor both isPalindrome and Extract methods work well: namespace Portable3 open FSharp open FSharp.Data open Microsoft.FSharp.Linq open FSharp.Data.FreebaseOperators open MyTrip.Model.MyTrip open MyTrip.Model.FreeBase open System.Runtime open System.Linq module math = let isPalindrome (str : string) = let rec check(s : int, e : int) = if s = e then true elif str.[s] <> str.[e] then false else check(s + 1, e - 1) check(0

F# Error compiling

。_饼干妹妹 提交于 2019-12-20 03:53:20
问题 I have the following F# Code that is causing a compile error: persistence.fs(32,21): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. The error is at the line "serializer.write...." Any help would be appreciated. namespace persisitence open System.Collections.Generic open System open System.IO type

What is currying in F#? [duplicate]

喜夏-厌秋 提交于 2019-12-20 03:31:43
问题 This question already exists : Closed 9 years ago . Possible Duplicate: Functional programming: currying I'm reading the free F# Wikibook here: http://en.wikibooks.org/wiki/F_Sharp_Programming There's a section explaining what Partial Functions are. It says that using F# you can partially use a function, but I just can't understand what's going on. Consider the following code snippet that is used an example: #light open System let addTwoNumbers x y = x + y let add5ToNumber = addTwoNumbers 5

What am I doing wrong with Set.Fold F#

怎甘沉沦 提交于 2019-12-20 03:26:04
问题 Colouring problem : Hello, I'm trying to implement a bool function that returns true when a color can be extended to a country and false otherwise but I'm having trouble working with sets as we cannot pattern match them... My code : type Country = string;; type Chart = Set<Country*Country>;; type Colour = Set<Country>;; type Colouring = Set<Colour>;; (* This is how you tell that two countries are neghbours. It requires a chart.*) let areNeighbours ct1 ct2 chart = Set.contains (ct1,ct2) chart

Euler 23 in C#: 0.2 seconds, in F#: 30.5 seconds. Why?

会有一股神秘感。 提交于 2019-12-20 03:11:33
问题 I am not really satisfied with my F# solution to this problem because I can't find a beautiful & fast solution, but that's not the issue here. The issue is, I translated the solution to C# for the heck of it, and it is fast. Like, really fast, comparatively. I can't figure out why. Yes, I've been to Reflector, C# code looks very similar, can't say I really understand IL but it looks kinda like the same. The only thing I can think of is performance of F# int[] against C# List. So here it goes:

F# -> Implement IComparable for HashSet<'a>

扶醉桌前 提交于 2019-12-20 02:58:13
问题 Is it possible to somehow implement IComparable for a HashSet<'a> ? The reason for this is that I have following record declared: [<StructuralComparison>] type Category = { mutable Id: string; Name: string; SavePath: string; Tags: HashSet<Tag> } and Tag = { Tag:string; } As you can see, then Tags in the Category record is of type HashSet<Tag> - and in order to map a sequence of Categories to a Map, I'll need to implement the IComparable somehow... else it will just result in: The struct,

How to combine equal sequence elements (functional programming)?

妖精的绣舞 提交于 2019-12-20 02:44:31
问题 I want to write a function that takes in a sequence <1,1,2,2,3> and returns the sequence with equal elements grouped like <<1,1>, <2,2>, <3>>. I'm using sequences, not lists, but some of the functions are similar. Some of the functions I am thinking of using are map, reduce, tabulate, filter, append etc.. Reduce takes in an associative function and returns the sequence that is "reduced" by that operator. So, reduce op+ 0 <1,2,3> = 6. My first thought was to use map to raise the sequence by

Bitmap image manipulation

流过昼夜 提交于 2019-12-20 02:39:10
问题 I want to replace GetPixel and SetPixel using LockBits method, so I came across this F# lazy pixels reading open System.Drawing open System.Drawing.Imaging let pixels (image:Bitmap) = let Width = image.Width let Height = image.Height let rect = new Rectangle(0,0,Width,Height) // Lock the image for access let data = image.LockBits(rect, ImageLockMode.ReadOnly, image.PixelFormat) // Copy the data let ptr = data.Scan0 let stride = data.Stride let bytes = stride * data.Height let values : byte[]

Why Seq.tail is not an option

99封情书 提交于 2019-12-20 02:31:19
问题 My question is when entering Seq. why is there no Seq.tail function? In this code that does not convert a sequence to a list, there is no Seq.tail function available in the recursive function. Is it because Seq.initInfinte was used to to create the sequence, or is there another reason? open System let readList() = Seq.initInfinite (fun _ -> Console.ReadLine()) |> Seq.takeWhile (fun s -> (s <> "")) |> Seq.map (fun x -> Int32.Parse(x)) let rec listLen list1 acc = if Seq.isEmpty list1 then acc

Splitting a list into list of lists based on predicate

。_饼干妹妹 提交于 2019-12-20 02:28:22
问题 (I am aware of this question, but it relates to sequences, which is not my problem here) Given this input (for example): let testlist = [ "*text1"; "*text2"; "text3"; "text4"; "*text5"; "*text6"; "*text7" ] let pred (s:string) = s.StartsWith("*") I would like to be able to call MyFunc pred testlist and get this output: [ ["*text1";"*text2"]; ["*text5";"*text6";"*text7"] ] This is my current solution, but I don't really like the nested List.revs (ignore the fact that it takes Seq as input) let