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

learn more… | top users | synonyms

2
votes
1answer
101 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
2answers
85 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
99 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
61 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
140 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
76 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
70 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
56 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
165 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 ...
2
votes
1answer
82 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
80 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
243 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
211 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
162 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
212 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
132 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
122 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
94 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
251 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
133 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
613 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
66 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
220 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
232 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
381 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
148 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
383 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
277 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
209 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
336 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
330 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
599 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
250 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
409 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
251 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
395 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 ...