Questions tagged [f#]

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

Filter by
Sorted by
Tagged with
2 votes
1 answer
130 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 ...
JDB's user avatar
  • 158
4 votes
3 answers
780 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 ...
p.s.w.g's user avatar
  • 1,961
4 votes
1 answer
98 views

is there a more functionally idiomatic way of generating valid dates in f#?

...
Vijesh's user avatar
  • 99
2 votes
1 answer
106 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 ...
Stuart Gordon's user avatar
3 votes
1 answer
820 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 ...
Stuart Gordon's user avatar
1 vote
2 answers
322 views

Async querying SQL in IIS

...
Jack Fox's user avatar
  • 111
2 votes
3 answers
2k 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 ...
Tommy's user avatar
  • 225
3 votes
1 answer
360 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 ...
8 votes
1 answer
1k 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 ...
Trident D'Gao's user avatar
2 votes
2 answers
461 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 ...
Coding Dude's user avatar
2 votes
1 answer
374 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: ...
TooTone's user avatar
  • 153
1 vote
1 answer
2k 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 ...
acarlon's user avatar
  • 283
6 votes
2 answers
608 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: ...
Ronnie Overby's user avatar
2 votes
1 answer
166 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 ...
bradgonesurfing's user avatar
8 votes
3 answers
358 views

Call an F# function with its previous result until the output no longer changes

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 ...
Wesley Wiser's user avatar
3 votes
2 answers
387 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 for 0.8s. As a learning practice, I translated it into F#. ...
colinfang's user avatar
  • 521
4 votes
3 answers
434 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 ...
Torbjørn's user avatar
  • 512
2 votes
1 answer
556 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. ...
dgp's user avatar
  • 21
5 votes
1 answer
306 views

Kata: Natural Sort

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 ...
JasonKerney's user avatar
2 votes
2 answers
171 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 ...
M Falanga's user avatar
  • 268
0 votes
1 answer
106 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 ...
M Falanga's user avatar
  • 268
1 vote
1 answer
294 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 ...
cnd's user avatar
  • 157
2 votes
2 answers
775 views

How to improve this array manipulation function? [closed]

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 ...
colinfang's user avatar
  • 521
4 votes
1 answer
1k views

Conway's Game of Life in F#

Since I'm learning F# along with functional programming, I managed to implement the rules for Conway's Game of Life. I'm not sure if I can improve some of its parts, though. For example, the ...
viniciushana's user avatar
4 votes
1 answer
157 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) ...
colinfang's user avatar
  • 521
4 votes
1 answer
3k views

Unblock Me / Rush Hour solver

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. Unblock Me / ...
colinfang's user avatar
  • 521
5 votes
1 answer
779 views

Rewriting C# implementation of Snake class in F#

This is my C# class, which takes 2.6s: ...
colinfang's user avatar
  • 521
5 votes
1 answer
207 views

Determining directions for a 2D boad

My original code is: ...
colinfang's user avatar
  • 521
2 votes
2 answers
2k 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 ...
Jimmy Hoffa's user avatar
  • 1,545
2 votes
3 answers
180 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 ...
Dmitri Nesteruk's user avatar
2 votes
1 answer
253 views

Getting prices and volume

I'm learning F# 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 elsewhere: ...
Simon Woods's user avatar
4 votes
1 answer
413 views

Three implementations of mergesort in F#

I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage? First solution ...
nicolas's user avatar
  • 171
5 votes
1 answer
1k views

Path sum - Dijkstra's algorithm in F#

I'm learning F# and I've decided to solve Project Euler's Problem #81 with Dijkstra's algorithm. In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by only ...
Asik's user avatar
  • 321
3 votes
1 answer
303 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) ...
Davin Tryon's user avatar
6 votes
1 answer
3k 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: ...
J D's user avatar
  • 263
7 votes
1 answer
1k 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 ...
Andy Hunt's user avatar
  • 447
2 votes
2 answers
346 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 ...
Gene Belitski's user avatar
3 votes
1 answer
1k views

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 ...
user avatar
3 votes
1 answer
766 views

String calculator in 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. The kata I was working on is ...
Jason w's user avatar
  • 133
3 votes
1 answer
717 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. ...
Henrik's user avatar
  • 81
4 votes
2 answers
901 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 ...
Frames Catherine White's user avatar
3 votes
2 answers
524 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: ...
Frames Catherine White's user avatar
9 votes
1 answer
758 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 ...
Derek Ealy's user avatar
6 votes
3 answers
495 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 ...
user avatar
11 votes
1 answer
923 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: <...
Stephen Swensen's user avatar
4 votes
1 answer
357 views

Processing a tab-delimited file with vertexes and ages

The following block of code needs to be as fast as possible as it likely to be called many thousands of times in a run. I am also conscious that my thinking style is leaning towards a more procedural ...
Vijesh's user avatar
  • 99
7 votes
1 answer
1k views

Map implementation in F#

Just as a refresher I put together a simple Map implementation and I would love to get some feedback on it. ...
ChaosPandion's user avatar
  • 1,753
6 votes
1 answer
434 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 ...
Mongus Pong's user avatar
10 votes
1 answer
529 views

Getting the last date where a given week day occurred

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 ...
tucaz's user avatar
  • 335

1
3 4 5 6
7