f#

F# How to tokenise user input: separating numbers, units, words?

会有一股神秘感。 提交于 2019-12-21 20:26:05
问题 I am fairly new to F#, but have spent the last few weeks reading reference materials. I wish to process a user-supplied input string, identifying and separating the constituent elements. For example, for this input: XYZ Hotel: 6 nights at 220EUR / night plus 17.5% tax the output should resemble something like a list of tuples: [ ("XYZ", Word); ("Hotel:", Word); ("6", Number); ("nights", Word); ("at", Operator); ("220", Number); ("EUR", CurrencyCode); ("/", Operator); ("night", Word); ("plus",

Can't load FSharp.Core version 4.0.0 in infer.net fun // hard link dependency in a dll ?

雨燕双飞 提交于 2019-12-21 20:14:07
问题 I am trying Infer.Net (An F# Library for Probabilistic Programming) And running the examples in VS11 Beta lead to the error : Could not load file or assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. If I open the dlls used the infer.net samples in Reflector, one, probcomp.dll, says it can not find automatically "FSharp.Core, Version=4.0.0.0"and that I need to select the location by

Point-free style with objects/records in F#

本秂侑毒 提交于 2019-12-21 20:12:23
问题 I'm getting stymied by the way "dot notation" works with objects and records when trying to program in a point-free functional style (which I think is a great, concise way to use a functional language that curries by default). Is there an operator or function I'm missing that lets me do something like: (.) object method instead of object.method ? (From what I was reading about the new ? operator, I think it works like this. Except it requires definition and gets into the whole dynamic binding

Attempting to use continuation passing style to avoid stack overflow with minimax algorithm

白昼怎懂夜的黑 提交于 2019-12-21 17:48:09
问题 Summary of my objective: Figure out how to use continuation-passing style to avoid a stack overflow when using an algorithm I believe cannot be made tail-recursive. Alternatively, find a way to make the function tail-recursive. Details: I am new to F# (and functional programming in general) and I am attempting to implement the minimax algorithm with alpha-beta pruning. This is an algorithm used to determine the best possible move for a two-player game. The pseudocode for the algorithm can be

help me reason about F# threads

随声附和 提交于 2019-12-21 17:45:47
问题 In goofing around with some F# (via MonoDevelop), I have written a routine which lists files in a directory with one thread: let rec loop (path:string) = Array.append ( path |> Directory.GetFiles ) ( path |> Directory.GetDirectories |> Array.map loop |> Array.concat ) And then an asynchronous version of it: let rec loopPar (path:string) = Array.append ( path |> Directory.GetFiles ) ( let paths = path |> Directory.GetDirectories if paths <> [||] then [| for p in paths -> async { return

Record with parameterless constructor?

早过忘川 提交于 2019-12-21 17:29:54
问题 I'm trying to build a web app (ASP.NET MVC3) that uses Entity Framework, and I've once again hit a wall. It throws following exception when trying to run a foreach loop over the collection in the view: System.InvalidOperationException: The class 'GvG.Entities.News' has no parameterless constructor. Now is my question, is it possible to somehow define a parameterless constructor on my record type? My record type at the moment looks like: type News = { mutable ID:int; mutable Author:string;

How can I hide methods in F#?

你。 提交于 2019-12-21 17:14:29
问题 I am currently implementing a Spec framework in F# and I want to hide the Equals, GetHashCode etc. methods on my should type, so that the API is not cluttered with these. I know in C# it is done by making the class implement an interface like this: using System; using System.ComponentModel; public interface IFluentInterface { [EditorBrowsable(EditorBrowsableState.Never)] bool Equals(object other); [EditorBrowsable(EditorBrowsableState.Never)] string ToString(); [EditorBrowsable

How can I hide methods in F#?

六月ゝ 毕业季﹏ 提交于 2019-12-21 17:09:12
问题 I am currently implementing a Spec framework in F# and I want to hide the Equals, GetHashCode etc. methods on my should type, so that the API is not cluttered with these. I know in C# it is done by making the class implement an interface like this: using System; using System.ComponentModel; public interface IFluentInterface { [EditorBrowsable(EditorBrowsableState.Never)] bool Equals(object other); [EditorBrowsable(EditorBrowsableState.Never)] string ToString(); [EditorBrowsable

How to test functions in f# with external dependencies

。_饼干妹妹 提交于 2019-12-21 17:01:41
问题 I am having a hard time trying to unit test F# code with external dependencies. In C# (my background) you would typically have a class with a dependency passed in, which is then re-used. Apologies for my sample code, it's dumb but I'm just trying to illustrate my point. public class Foo { IDependency d; public Foo(IDependency d) { this.d = d; } public int DoStuff(string bar) { return d.DoSomethingToStuff(bar); } public int DoMoreStuff(string bar) { int i = d.DoSomethingToStuff(bar); return d

Parsing “x y z” with the precedence of multiply

非 Y 不嫁゛ 提交于 2019-12-21 16:52:45
问题 I'm trying to write a parser for the Mathematica language in F# using FParsec. I have written one for a MiniML that supports the syntax f x y = (f(x))(y) with high precedence for function application. Now I need to use the same syntax to mean f*x*y and, therefore, have the same precedence as multiply. In particular, x y + 2 = x*y + 2 whereas x y ^ 2 = x * y^2 . How can this be accomplished? 回答1: As Stephan pointed out in a comment you can split the operator parser into two separate parsers