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

learn more… | top users | synonyms

0
votes
1answer
54 views

Can this be made less repetitive or more idomatic F#?

I'm following http://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus/ ...
3
votes
0answers
32 views

Retrieve records from the database based on a possible id

This code will retrieve all records from the database if the id is null or return records by the available id. Is there a way to combine the query instead of having two separate queries? ...
3
votes
0answers
29 views

Check the database for an order number

This code will check the database for an order number. If none exist it creates one. If one does exist then it will increment it by one and update the database. Is this the most efficient way to ...
3
votes
2answers
78 views

Making backtracking Sudoku solver more functional

I'm implementing the backtracking solving algorithm for a Sudoku in F#. I'm wondering if I could make my code better respect the functional programming paradigm or even just making it simpler/better. ...
1
vote
0answers
69 views

Traffic Flow functional way

The same problem, but f# instead c#: ...
1
vote
1answer
75 views

SalesTax problem

The same problem, but I decided to do it using F#: ...
2
votes
1answer
59 views

Organizing types/namespaces within tree

I'm working on a parsing engine as part of a personal project, and I'd like to expose certain .NET APIs to the parsed environment. I put together a very simple tagged union that allowed me to nest ...
1
vote
1answer
72 views

Is this use of ConcurrentDictionary truly thread safe?

I'm working on some teaching examples showing the perils of accessing the Dictionary class concurrently. In the code below each function is designed to do a word count across a number of files. ...
2
votes
2answers
143 views

Check database for item and create it if it doesn't exist

Is there a more efficient approach to this code? ...
2
votes
0answers
53 views

Polling, parsing, validating and handling data cleanly and efficiently

<edit: There's a major problem in the code. It is basically the one in the comment regarding backpressure. I'll rework the code within a a few days... It's time for a quick code review, good ...
2
votes
2answers
88 views

A concurrency-safe stack structure

This is a teaching sample intended to illustrate use of mutability and list consing in F#. The structure is intended to be a thread-safe stack structure, which multiple threads can push to/pop from ...
4
votes
1answer
36 views

Server code to save uploaded files

This code basically saves an uploaded file to the server. I am wondering if there is anything that I can do to tighten this code up. I am very new to F# so I'm still having trouble breaking away ...
3
votes
1answer
97 views
1
vote
1answer
89 views

Basic templating engine in F# using F# syntax

I've been working on a rough idea for a templating engine (mostly as a learning project) using the F# syntax. How "correct" is my code in terms of being idiomatic F#? Are there F# features which would ...
6
votes
4answers
192 views

Splitting a sequence into equal segments

I need to split up a sequence into equal segments of a given size (yes, the last one may be shorter), and I'm trying to find an efficient and idiomatic way to do it. I have two versions of the ...
14
votes
2answers
582 views

First real-world F# application - how “good”/idiomatic is it? (long!)

After reading/watching various introductions and blog posts and some code here and there, doing a bit of the Try F# tutorial and starting to read "Real World Functional Programming", I felt I should ...
3
votes
0answers
88 views

Simple RabbitMQ client wrapper

After reading this question, I've realized that I can do a lot to improve the quality of my question, so I've edited this question quite a bit. I've been teaching myself F# in my spare time off and ...
7
votes
3answers
159 views

Poker Hands Kata in F#

I'm a F# newbie, and would like to share my implementation of the Poker Hands Kata problem to get some feedback. ...
7
votes
1answer
142 views

Hierarchical State Machine in F#

I appreciate any feedback on where I might alter or improve my code for this project. This is an old attempt at implementing a Hierarchical State Machine in F#. I'm from a C#/OO background mostly. ...
2
votes
1answer
101 views

Is this a good use of Async in F#?

I've hacked together some code to read the content from a sequence of files: ...
1
vote
0answers
40 views

What is the difference in these implementations? [closed]

While porting some C# to F# I wrote this code: ...
4
votes
0answers
136 views

F# and Rx code that throttles; can it be done without ref cells (and possibly with active patterns)?

I'm basically redoing a piece of reactive C# code posted in SO code in F#, please, see below. The translation is fairly literal, I've just written the infinite loop as a recursive function and ...
5
votes
1answer
106 views

Read text from stream char by char

I've started learning F# and functional programming in general, but the code I wrote doesn't seems to be really functional. Could you take a look and say how to make it more as it should be in ...
6
votes
4answers
254 views

Functional approach to splitting list into sub lists

Here is my functional approach to split a list into sub lists, each having non-decreasing numbers, so the input \$[1; 2; 3; 2; 4; 1; 5;]\$ computes to \$[[1; 2; 3]; [2; 4]; [1; 5]]\$ The code ...
6
votes
1answer
200 views

Reading input from the console in F#

In the process of learning F#, I wrote this code that reads lines of input from the console and stores them in a list. As far as I can tell the code works correctly, but since I'm new to functional ...
4
votes
2answers
111 views

F# rectangle packing algorithm

I would appreciate it if someone experienced in F# and/or functional programming to look over my code. This is practically the first thing I wrote in the language so I'm sure it's filled with ...
1
vote
0answers
132 views

Review my F# Red Black Tree Implementation [closed]

I have written this implementation for red black tree. I also have some helper methods to verify whether the generated tree is really balanced or not. Looks good to me.... but I find that most of the ...
1
vote
1answer
132 views

Review my F# QuickSort Program

OK... last sort of the day and probably the most fun. F# is really awesome. ...
1
vote
1answer
112 views

Merge Sort Program

I have written the following program to implement merge sort in F#. Can you please review this and let me know how can I write this in the most functional way (also most efficient and concise)? In ...
1
vote
2answers
61 views

Review my F# BubbleSort Program

I have written this code for BubbleSort in F#. Can you review and let me know how I can do this in most functional way. ...
4
votes
2answers
50 views

InsertSort F# program

I have written this InsertSort program in F#. It works, but I am not very happy with it. ...
2
votes
1answer
70 views

Using types in F#

I've played with F# for over a year, but I've only recently begun tentatively using it for professional work. I'm concerned that my c-style OOP principles are blinding me to the advantages of a ...
4
votes
3answers
132 views

Improving F# conditional assignment with match expression

In my code I declared a dictionary to store various counters let counters = Dictionary<Type, int>() Later, I need to generate several labels using these ...
2
votes
1answer
94 views

parallel.For function

I am trying to add parallelism. The following function works. For testing purposes, calculating chunckLength is fine. However, when I allocate more cores, it seems ...
2
votes
1answer
147 views

Barnes-Hut implementation of the N-Body problem translated from F# to C#

I am after a peer review of a C# implementation of the Barnes-Hut algorithm which I have translated from F#. The F# version is the base for comparison, therefore the C# version is suppose to reflect ...
1
vote
2answers
157 views

Async querying SQL in IIS

...
2
votes
3answers
719 views

Project Euler Problem 7: Find 10001st prime number

I was able to complete the problem, but I would like to improve my code and make it more idiomatic. Here is the challenge description: Problem 7 - 10001st prime By listing the first six ...
3
votes
1answer
274 views

Coding Functional style taking longer time than its Imperative style

I wanted to try out F# so I decided to I converted a library file from c# to f#. I have done that successfully(thanks a you people in stackoverflow). At first I ported the code from c# to f#. Than I ...
6
votes
1answer
275 views

Discriminated-unions in C#

So I really want to have something similar to discriminated unions in C#. One way to do it is to use a visitor pattern, but it takes half a life to write all broilerplate code by hands. There is ...
2
votes
2answers
92 views

Recursive function refactoring help: occurrences of char in string starting at ith char

Just getting into functional programming and F# with the most appropriately titled Functional Programming Using F#. I wrote the following function definition for problem 2.4 but I'm thinking there's ...
1
vote
1answer
93 views

How to use pattern matching within curried function

I'm learning F# and I'm trying the following exercise (exercise 4.10 of Functional Programming Using F#). Declare an F# function prefix: ...
0
votes
1answer
211 views

F# solution to generic new() constraint limitation

Today I decided to get into F#. I watched this video and had a bit of fun doing some coding examples, I can see that it will be very useful for certain programs that I write. One thing that I was ...
4
votes
2answers
303 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: ...
2
votes
1answer
153 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 ...
7
votes
2answers
252 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 ...
2
votes
2answers
221 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
166 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
256 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
153 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. ...