Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [f#]

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

2
votes
1answer
193 views

Simple actor system in F#

Any thoughts on my actor model here? Obviously it doesn't have implementation for concurrency as it stands- being completely synchronous, but it should be easy to make the send/become/create be sent ...
3
votes
2answers
653 views

Longest Common Subsequence and Longest Subsequence Palindrome

The following code computes: The longest common subsequence between two strings, where a subsequence of a sequence does not have to consist of contiguous elements of the sequence. The longest ...
5
votes
1answer
317 views

The Functional FizzBuzz Kata

I run a coding dojo at work. For one session I'm to showing that you can use a kata to get into a new language. I'm using the FizzBuzz Kata to to show F# (and JavaScript) because it is short. The ...
4
votes
2answers
303 views

Excel calculation engine

We have currently rewritten an Excel calculation engine in F# and are looking to refactor the code to make it a lot more idiomatic and standardised. One of the big problems with the code is that we ...
3
votes
2answers
194 views

Idiomatic and Conventional F#

As of late I have been learning F#. Today I accumulated what I have learned so far to develop my first program - a script that counts the number of lines of code in a given Visual Studio project. ...
1
vote
1answer
76 views

Searching for files across multiple code projects

I was tasked with conducting a large number of text searches in the code files of multiple projects. Initially, I just used the Find in Files feature of Visual Studio in a couple of the running ...
3
votes
2answers
938 views

Split string into parts of varying lengths

I need to split a string into parts of varying predefined lengths, given as a sequence of integers. After a first imperative attempt using a sequence expression and a reference cell, I have now come ...
5
votes
2answers
253 views

'Countdown' Numbers round - combine numbers arithmetically to reach a target

Countdown is a British gameshow where contestants compete in word and number challenges. During the numbers round, six numbers are chosen semi-randomly and the task is to combine them using addition, ...
4
votes
1answer
290 views

Detecting connected acyclic through Tarjan strongly connected components variant

I want to verify that a given directed graph is connected and acyclic (DAG). I have implemented a modification of the Tarjan's strongly connected components algorithm in imperative style (as the ...
4
votes
2answers
340 views

Detecting properly nested parenthesis using functional programming

So I have this code that is my attempt at a coding test from Codility. While my code produces correct results according to the requirements, (which unfortunately are copyrighted so I don't think I can ...
4
votes
1answer
2k views

Join() equivalent function for F# sequences

I am porting C# code to F# that makes use of LINQ's Join() extension method. Just as I use that in method call chains, I would of course like to have an F# function ...
3
votes
2answers
393 views

Tail-recursive query string builder in F#

I have a situation where I'm generating a URL based on a set of query string parameters for use in an API. I know ahead of time that the values passed to this function are URL-safe and the tuples are ...
6
votes
1answer
587 views

Good usage of MailboxProcessor/Agent in class rather than mutable field?

I've written a simple Simple Service Discovery Protocol (SSDP) module. This module contains a class, Session that you create and then use to issue commands and ...
3
votes
1answer
104 views

Testing whether a matrix contains a submatrix

As part 2 of my other question concerning this long running project I've been inquiring about on CR, I reimplemented my generic function for determining if an array of arrays is a sub-array or ...
3
votes
1answer
169 views

Refactoring while-do into tail recursion with F#

I have a while-do loop nested inside a while-do loop in my program, due to it needing to iterate in two dimensions through an array of arrays, and originally my loop looked like this: ...
7
votes
3answers
320 views

Functional Programming style in F#

I'm normally a C# developer, but I've started to learn F# and I want to make sure I'm writing code in a functional way that suits the language. I've quickly pieced this together with my knowledge from ...
6
votes
2answers
88 views

Discount curve from instant rate

This my first foray in F#, and I cannot think (yet) functional. I have implemented an interface for a discount curve and the implementation for a piecewise constant instant rate implementation. I ...
3
votes
1answer
154 views

Locating a bitmap inside another (larger) bitmap with F#

This is my firstish (heavily rewritten) go at the completed project that I've been working on with CodeReview assistance, so further advice is appreciated! See here, here and here for the past history ...
2
votes
2answers
485 views

Replacing an F# loop over a mutable variable by an immutable approach

Consider: let mutable m' = m while m' % i = 0L do m' <- m' / i I've refactored it into: ...
4
votes
1answer
131 views

Transform Bitmap object into jagged array of RGB tuple values

I've been working on this module with the assistance of codereview, and based on the responses and my own research, this is my project so far. The goal behind the code is that it starts with a .NET ...
11
votes
1answer
250 views

Ugly Numbers: A Rags-to-Riches Story

I stumbled upon an unaswered question, which looked like a good fit for a functional programming language. Here is the problem statement from codeeval: UGLY NUMBERS CHALLENGE DESCRIPTION: ...
5
votes
1answer
171 views

Generating the pretty bit at the end of a URL

I'm having a dip into F# and am attempting not to write it like it's C#. One area that bothers me is using members of System.String. These often need to be chained ...
3
votes
1answer
335 views

Transforming a byte array into an array of byte arrays with F#

This code is intended to be used with an image manipulation library that I'm working on, and the goal is to take the raw byte[] data from an image, and transform it into a 2D array where each position ...
1
vote
1answer
175 views

Load bitmap object data into array of byte values

I'm building this as part of a larger class to rapidly search for smaller images inside larger images. This is my first serious F# project so comments especially concerning style and organization are ...
4
votes
1answer
398 views

A functional binary heap implementation

I've implemented a binary heap in F#. It's pure and uses zippers for tree modification. To test it out I have implemented heap sort using it but it takes 10 seconds to sort a list of 100 000. Regular ...
4
votes
1answer
842 views

Fibonacci number function: convert to tail-recursion?

I've been implementing a function for calculating the nth Fibonacci number in F#. So far the best implementation I could come up with is this: ...
4
votes
1answer
515 views

Parsing sections from a log file using F#

After reading a lot about F#, I am today cutting my very first real life F# code and I'd appreciate any feedback on my approach. I'm writing a simple utility to analyse a log file. The code below ...
2
votes
2answers
116 views

Defining a zip code string

I'm following this ...
3
votes
0answers
55 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
61 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 ...
4
votes
2answers
773 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. ...
4
votes
1answer
152 views

Traffic Flow functional way

This problem: The Shallow Alto city council has organized a special committee to review the traffic situation in the city. Despite the fact that there is nothing whatsoever to do in the city, ...
1
vote
1answer
138 views

SalesTax challenge

This is the same problem, but I decided to do it using F#. I'm just interested in how I can improve it. ...
2
votes
1answer
80 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 ...
2
votes
1answer
1k 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
407 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
308 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
368 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
101 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
600 views

NinjectWebCommon implementation/translation - C# to F#

I've translated this code from c# and would like it to be more idiomatic f#: ...
1
vote
1answer
630 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
3answers
1k 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 ...
24
votes
2answers
2k 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 ...
7
votes
1answer
707 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 ...
13
votes
3answers
1k 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
798 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
481 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: ...
4
votes
0answers
319 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
565 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 ...
9
votes
4answers
3k 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 ...