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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

4
votes
1answer
45 views

Async/Await Computation Expression

When writing asynchronous code in F#, one often needs to call methods in the .NET BCL that return Task or Task<T> rather ...
10
votes
3answers
146 views

Generating image gauges from a value, min and max

One of the things I was recently investigating was the ability to generate "gauge" charts—that is, a chart which shows where a value stands within a range of values. As an example, if we know ...
4
votes
3answers
150 views

Implementing class equality/comparison in F#

I'm working on some book material on classes and interfaces in F#. My example is a latitude/longitude class: ...
4
votes
0answers
37 views

Hierarchy (Family Tree) Domain Model

I'm wanting to model a family tree in the F# type system. The basic requirements: A family tree is made up of family members A ...
5
votes
1answer
110 views

Simulating coin flips and plotting a histogram

I started playing around recently with F# and I find it quite elegant and succinct language. A common problem I like to solve in every language I start to learn is the coin flip problem, with the ...
2
votes
0answers
38 views

Business Rule DSL for Values in Domain-Driven Design

Following the patterns from the book Domain Modeling Made Functional, I am implementing a single-case union for the simple values in my domain model instead of using primitives. The union cases have ...
4
votes
0answers
96 views

Backtracking solver for n queens problem and knight's tour

Playing with https://ocaml.org/learn/tutorials/99problems.html#Miscellaneous-Problems I wrote a backtracking solver for the n queens problem, then the knight's tour, and realised I could generalise ...
3
votes
0answers
60 views

Lock-free Immutable ConcurrentQueue

Similar to the code review I posted last week for an agent-based immutable replacement for ConcurrentDictionary, I have also created an agent-based immutable ...
5
votes
0answers
77 views

Agent-based Immutable Map

I am in the process of removing the last few pieces of mutable state from an F#-based distributed system. Some of the remaining mutable state is a ...
3
votes
0answers
92 views

Queue-based fixed-duration memory cache

I used to use the MemoryCache in .Net but recently read about a DB using using a linked-list, which only had to check the prefix of the list in \$O(1)\$ complexity, to time values out, as opposed to ...
7
votes
1answer
114 views

F# Either computation expression with while loop

I want to implement an Either computation expression in F#. The computation executes a function inside a while loop, and this function's return type is ...
3
votes
0answers
45 views

Work environment simulator

This code attempts to solve a suggested challenge by myself a while back on meta, transcribed here for simplicity. Allocate resources efficiently on a work environment The company Code42Review ...
3
votes
1answer
47 views

Pair up elements of a sequence without overlap

I have a sequence (in this case actually an array) like this: [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10|] And want to produce a sequence of pairs like this: ...
2
votes
1answer
69 views

Is It In Its Prime?

Just because I'm bored, I wrote yet another prime number generator. I think it's pretty clean, but I won't be surprised if someone finds something to comment on. ...
3
votes
1answer
122 views

AutoMapper DSL (Computation Expression) for F#

I have created a DSL for AutoMapper using an F# Computation Expression Builder. The Computation Builder itself is fairly simple, and effectively defines 5 basic operations: ...
6
votes
2answers
73 views

12 Days of Christmas with F#

I've implemented 12 Days of Christmas just by using pattern matching. It's not very efficient as it performs 12 iterations, each performing its own iteration (potentially from 12 down to 1... does ...
0
votes
0answers
46 views

Functional permutation generator

I have (we have) implemented the functional permutation generator from (Topor, 1982). The full source of the implementation is here. As usual I would like feedback on how to make the code more ...
1
vote
0answers
34 views

HTTP request call for a token

The following code seems to have several redundant Flush, Close and Abort statements despite ...
2
votes
3answers
83 views

Implementation of Permutation Algorithm B from Topor, 1982

This is Algorithm B from Functional Programs for Generating Permutations (Topor, 1982). We have implemented Algorithm B in an F# recursive module as follows. ...
2
votes
1answer
89 views

Mocking an F# primality tester

I would like to ask 2 questions about the modularization of an F# file. The code is just a working example of prime factorization, but that's not the main topic. I have a main file (PrimeFactors.fs), ...
4
votes
1answer
112 views

FizzBuzz in F# with functional programming

Learning F#, created a somewhat elaborate fizzbuzz-builder implementation to see if I'm starting to "get" F# and thinking functionally: ...
1
vote
1answer
43 views

Inspectors & Deconstruction on Unions in a list

I am still new to functional programming and found myself trying to filter and map a list of discriminating unions. I could be wrong, but it started to feel very unnatural to do this. I just couldn'...
5
votes
2answers
160 views

Implementation of Permutation Algorithm A from Topor, 1982

This is Algorithm A from Functional Programs for Generating Permutations (Topor, 1982). The author states that the algorithm was described in TAoCP Vol 1. We have implemented Algorithm A in F# as ...
1
vote
0answers
56 views

Immutable Queue with Bulk-Enqueue

I recently needed a data structure with FIFO queue semantics that supported efficient bulk-insertion (often need to enqueue thousands of messages at once). I took a look at Purely Functional Data ...
0
votes
1answer
99 views

Count the number of digits in an integer using F# and log10

This code counts the number of digits in an integer. let digitCount number = (int) (log10 ((float)number)) + 1; For instance, it tells us ...
4
votes
1answer
44 views

Generating the Collatz sequence in F#

Below is my code for building the collatz sequence so a given number. I'm trying to make the function tail recursive and I believe that this impelemtation is tail recursive but I'm not yet so ...
4
votes
2answers
120 views

Generating abbreviations for strings

One of many aspects of a project I am responsible for is generating an abbreviation, that is no more than n characters, for a given string. We use this in the ...
1
vote
0answers
67 views

F# Operation Framework (Railway-Oriented Programming + Task/Async/Lazy)

I recently published the initial version of what is effectively my first open-source software package, a Railway-Oriented Programming Framework for F# that encapsulates Tasks, Async Workflows, and ...
1
vote
0answers
41 views

Thread-safe hashset that enumerates according to insertion order

According to the .NET documentation, HashSet<T> does not maintain order when enumerated so I implemented my own using F#. Can anyone help review if this is ...
6
votes
1answer
146 views

Finding the first position in a number spiral that's bigger than a target

I'm working on day 3.2 of Advent of Code. The task for this challenge is to create a number spiral where each element is the sum of all of its neighbors. Using this spiral, we have to find the first ...
1
vote
0answers
42 views

Creating and manipulating a map for a text based game F#

I have put my whole code so far below, but what I am most interested in is how best to implement the map and utilise it. Any tips on organising my code and keeping it clean would also be greatly ...
1
vote
0answers
52 views

F# Finding the powerset of a set

I have this function which takes a list as input and computes the powerset. ...
0
votes
0answers
24 views

F# Inactivity Detection

I've written the following to detect inactivity - I'm going to be using this to detect when a heartbeat message has not been received in the last N milliseconds, however in this program I'm testing ...
5
votes
1answer
126 views

Brainfuck interpreter in F# (by a C# developer)

I'm a C# developer learning F#. I have a lot of questions about practices and principles within the code. I would like to know what a "native" F# developer would've done differently. ...
4
votes
3answers
262 views

Partitioning a list in F# based on whole group characteristics

I only started programming in F# yesterday, so I've not yet discovered what idiomatic F# actually looks like. The first task I set myself required partitioning a list into smaller lists but where the ...
0
votes
1answer
56 views

F# functions implementing polynomial arithmetic [closed]

I have a couple of functions for doing basic arithmetic on polynomials. ...
3
votes
1answer
70 views

Area under curve and its volume as solid of revolution

I would like to know if there is some more "elegant" way to write these 3 functions. Any tip or idea is welcome. ...
6
votes
2answers
240 views

Validate a password mostly to NIST-2017 standards

I have an application that needs to validate user passwords to a very reasonable custom validator, which is heavily based on NIST-2017 requirements. The validator intends to satisfy the following ...
3
votes
0answers
85 views

F# Observable.subscribeWeakly implementation

In this SO question I needed an observable subscription function that can be used kind of like Observable.subscribe, but that does not keep a strong reference to ...
8
votes
2answers
103 views

Wordpress RSS Parser

Follow Up to my earlier question. This is an RSS Parser intended only to parse the feed Wordpress provides (and even then, only what I actually want to display on my website). ...
5
votes
1answer
84 views

RSS Parser for Blog Feed

I'm building an RSS feed parser so, later, I can retrieve recent blog posts on my word press blog and display recent posts on my other website. This code isn't intended to implement the full RSS spec. ...
3
votes
0answers
99 views

Concurrency using immutability

I was watching the following video about software transactional memory(using a package that maintains an access log). At the moment I am trying to learn about concurrency with shared memory and ...
1
vote
0answers
82 views

Is This F# Recursive Example Tail Recursive?

I have a payment/lockbox file archiving utility that is called several times per day and with different parameters depending on the files that need archiving. I know I can flatten ...
2
votes
2answers
47 views

Minimise function with single minimum and no maximums

I'm learning F#. I wrote a function to minimise a function with a single minimum and no maximums. At the bottom I test it on Math.Cos. What do you think? I've wrote it pretty much as I would in an ...
4
votes
1answer
98 views

Counting letter frequencies from an input file

Out of pure curiosity, I decided to create a short F# script to calculate the letter frequencies based on the input file. Everything works smoothly and as I would expect. My questions regarding my ...
0
votes
1answer
36 views

Questions on F#'s loop and cont [closed]

The following tail-recursion example is taken verbatim from Chris Smith's Programming F# 3.0. If this is not the appropriate forum for this post, I will gladly move the post to the appropriate place. ...
5
votes
1answer
221 views

Functionally find the index of the minimum value in an array

I come from a C#/JavaScript/TypeScript background and am learning F# by implementing fundamental algorithms. This is finding the minimum value in an array: ...
2
votes
1answer
279 views

Implement array element swap in a functional language

Sorting algorithms involve swapping element positions in an array. This is my implementation of swap: ...
2
votes
2answers
67 views

Immutable recursive binary search of a generic array

I am new to F#. Is the following code, which represents about three hours of work, a canonical way to achieve binary search? If not, how can it be improved for readability and maintainability? ...
5
votes
1answer
74 views

Learning F# with Prime Factorization

In my quest to learn F#, I implemented Prime Factorization. First, the code: ...