F# is a succinct, expressive and efficient functional and object-oriented language for .NET

learn more… | top users | synonyms

3
votes
1answer
72 views

Learning F# - Porting C# Function to F#

I'm an advanced C# programmer learning F#. As an exercise I'm porting a function that calculates the check digit of a US ABA (routing) number. Here are 2 C# implementations: int CalcCheckDigit(string ...
2
votes
1answer
133 views

Improve this numeric solver for properties of geometric objects

I'm converting some C# code to F#. Basically it is some geometry classes that can have properties tuned by a numerical solver. I start with a discriminated union of type parameter that can be fixed or ...
7
votes
2answers
209 views

What's the most idiomatic way to call a function an arbitrary number of times with the previous result?

Basically I have a function of the type 'a -> 'a (an optimization function on a AST) and I want to call it (passing the previous result) until it returns the same thing as the input. Right now I ...
2
votes
2answers
138 views

My implementation of lexicographic permutation in F# is 3x slower than C#?

Can someone help me with the following micro optimization for the f# code for lexicographic permutation? I have code in C#, which runs 0.8s in x86 and x64. As a learning practice, I translated it ...
3
votes
3answers
110 views

Idiomatic conditionals in F#

I'm learning F#, and even though I'm able to do whatever I want, parts of my code looks really bad. I would love to get some suggestions on how to improve a couple of functions involving some ...
1
vote
2answers
118 views

RGB Color Name Matching using Euclidean Distance (Improved)

The code below stems from work on a Euclidean Distance algorithm. The color table was simply a vehicle to test the algorithm. It is perhaps reinventing the wheel, however it is useful in itself. ...
2
votes
1answer
81 views

VB.Net interfacing with F# Euclidean Distance Algorithm

I testing F# code which calculates "nearness" of two N-dimensional points using a least square euclidean distance algorithm. The class library is written in F# and the calling will be from VB.NET. ...
3
votes
1answer
162 views

How to better format my F# code for readablility

I am choosing to learn F# for my own enjoyment. I am getting to the point where concepts of F# seem to be pretty easy, but understanding some of the whys and whens is a bit harder. Before I get into ...
2
votes
2answers
81 views

Using Types to Designing Domain

I am trying to model a domain of metrics for use in a BI application. I recently read the Designing with Types series, and felt that it could be useful, so I wanted to give it a try. What I'm not ...
0
votes
1answer
74 views

Perfomance and Other Improvements

I am trying to wrap my arms around all the digital files we have, so I thought I would organize all of our pictures and videos into folders named after dates. I'm learning F#, and this felt like a ...
1
vote
1answer
60 views

TimeSpan don't support years so how do I deal with it? Is there could be smarter solution?

explain: from start day till now I've got 7.7 mb size, how long it will be to make it 10 gb size open System let dd = (DateTime.Now - DateTime.Parse("12/09/2012")).Days let oneday = 7.7 / ...
3
votes
3answers
235 views

How to improve this array manipulation function?

The function takes 2 arguments: array: int[], cap: int Members would be ranged from 0 to cap. e.g. array = [0,0,0,2,6,3,0,4,2,4,0] cap = 6 The return value is a new array of same length based on ...
3
votes
1answer
114 views

Better ways to implement Conway's Game of Life in F#

As I'm learning some F# along with functional programming, I managed to implement the rules for Conway's Game of Life but I'm not sure if I can improve some of its parts. For example, the neighbours ...
4
votes
1answer
82 views

How to refactor this groupby alike method but with index?

I have got such 2d jagged array (row is 1st dimension, column is 2nd dimension, bottom to up, left to right) 0 0 b b b c 0 0 h g g c 0 0 h a a c 0 0 f f d d 0 ...
3
votes
1answer
297 views

How to improve this unblock me / rush hour solver without any major change in search algorithm?

This is my first complete program written in F# (I was from C# and occasionally do interop) And I believe there are quite a few places I didn't tackle well in terms of coding practice. Problem ...
4
votes
1answer
241 views

Rewrite C# class in F# result in half performance, any suggestion?

This is my c# class takes 2.6s class Snake { readonly Symbol _mySymbol; readonly int _multiplier; readonly int _hit; readonly int _payout; readonly Snake _bestSnake; ...
4
votes
1answer
168 views

Is it worthwhile to simplify this code and how?

My original code is: let (upPosition, downPosition, leftPosition, rightPosition) = match myMove.MyDirection with | Direction.Up -> (GoUp y, y, GoLeft x, GoRight x) | ...
2
votes
2answers
241 views

simple stupid F# async telnet client

Did I write this code to correctly be tail call optimized? Am I forcing computations more than I need with !? Did I generally write this asynchronously correctly to allow sends and receives to occur ...
2
votes
3answers
135 views

Is there a better way of defining custom calendars?

I need to define custom calendars and, in particular, test a DateTime for being a holiday. My current code is shown below. Is there a more concise/better way of doing this, preferably without ...
1
vote
1answer
125 views

Refactor some F#

I'm learning F# atm and have a couple of routines much of whose functionality looks common so I am looking to refactor them together Here are the routines - (which for the record I lifted from ...
0
votes
0answers
116 views

F# mergesort code : where to improve

I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage? open System open System.Windows open System.Collections.Generic let shuffle (l:'a array) ...
3
votes
1answer
323 views

Dijkstra's algorithm in F#

I'm learning F# and I've decided to solve Project Euler's problem #81 with Djikstra's algorithm, in F#. This is the problem: http://projecteuler.net/problem=81 Is there any obvious mistake, ...
3
votes
1answer
138 views

Euler 2 : Simple Fibonacci

I'm just starting to experiment with F# (from a C# background). I think I'm starting to get into the right way of thinking, but this code still seems pretty awkward. Is there a better (more terse) ...
2
votes
1answer
650 views

Symbolic derivative in C#

I have translated the following F# code to C# and would appreciate constructive criticism. This code computes the symbolic derivative of the expression f(x)=x³-x-1: type Expr = | Int of int | Var ...
0
votes
0answers
71 views

Lots of similar classes F#

Ok I have a game that has a board, as some IMoves which are applies to the board to turn it into a new one. there are two placement moves Raise - remove one piece, and place another Place - just ...
6
votes
1answer
242 views

F# Djikstras shortest path implementation

I'm just getting my feet wet with F#, by implementing some simple algorithms. First up: Djikstras shortest path. There is one piece I've written in this code which confuses me as to why it works: the ...
2
votes
2answers
245 views

How can this functional implementation of Kadane's algorithm be improved?

Some time ago I posted on Stack Overflow an imperative C# implementation of Kadane's algorithm for finding a subarray with maximum sum. Then I considered implementing the same functionally in F# and ...
3
votes
1answer
465 views

F# basic neural network

I just programmed a basic neural network in F# to learn the logical OR function. As I am very new to F# and especially functional programming, I did it the imperative way. And even tho it works, I ...
3
votes
1answer
167 views

F# String Calculator - I am just Learning F#

This is some of my first real F# code ever. I have done a bit of reading and watched a few videos however. I chose to do a code kata for string calculator to try it out. I am pretty happy with this, ...
3
votes
1answer
411 views

Review an asynchronous/message-oriented library actor

I'd like to get input on a F# actor that coordinates receives around a blocking message buffer. The actor is a piece of code that continuously tries to fetch messages from Azure Service Bus. (* ...
3
votes
2answers
310 views

Immutable pure data classes with public setters on properties

I'm putting together some classes as a model for some information (that I'm currently pulling from a website). The classes are implemented in C# - because in the current version of F# there are no ...
3
votes
2answers
239 views

Using a Function to emulate F# Match in C#

So this was inspired by: this question But doesn't actually answer it: What do you think of: public class Case<TRes> { public Case(bool condition, Func<TRes> result) { ...
8
votes
1answer
349 views

Deleting from Red Black Tree in F#

Yes I'm very slowly making my way through Purely Functional Data Structures. So I went through the section on Red Black Trees. What he presents is amazingly concise, except for the fact that he didn't ...
5
votes
3answers
341 views

Is there any way to improve (shorten) this F# code?

I have a very good grasp of the syntax and features of F# as well as some of the concepts that mesh well with the language. However, I do not have enough experience writing it to feel comfortable that ...
7
votes
1answer
636 views

Approach to programmatically building hierarchical GUI components

At work I am developing an application using hand-coded Swing, and I've found that I have an easier time reading, writing, and maintaining hierarchical component creation using code blocks like: ...
5
votes
1answer
257 views

Can anyone offer tips on making code more performant and more functional

The following block of code needs to be as fast as possible as it likely to be called many 1000s of times in a run. I am also conscious that my thinking style is leaning towards a more procedural ...
6
votes
1answer
426 views

What do you think of my Map implementation?

Just as a refresher I put together a simple Map implementation and I would love to get some feedback on it. open System open System.Collections.Generic type Node<'a, 'b when 'a : comparison> = ...
4
votes
1answer
265 views

How can I make this F# more functional?

I am currently learning myself a little F# and have written the following code to practice. The code uses the Mono.Cecil library to inject some IL at the start of every method in each .net assembly ...
6
votes
1answer
402 views

Is this functional enough?

I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me. In one of my pet projects I'm dealing ...