Stack Exchange Network

Stack Exchange network consists of 175 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

5
votes
2answers
83 views

Roman Numbers - The Functional Way

Yet another exercise in converting values between the decimal and roman number systems. I have tried the functional way. Any comments are welcome - but I'm especially interested in answers focusing ...
3
votes
1answer
38 views
2
votes
1answer
52 views

F# parse data and calculate sum

I decided to play with F# and found simple task on Codewars. The task is sounds like "Calculate Sum/Mean/Avarage for selected City". I decided to calculate only Sum. My solution is horrific. I would ...
2
votes
1answer
50 views

Project Euler Problem #102 in F#: counting triangles that contain the origin

I've recently decided to get into functional programming with F#, and decided to learn the language through Project Euler. The following is my implementation of problem 102: Problem: Three ...
3
votes
1answer
229 views

Convert bitcoin value based on exchange rate from JSON API

I’m learning F# and trying to find a more ‘functional’ way to code a simple program that retrieves the price of BTC and calculates the EUR value of an amount of Bitcoin. ...
2
votes
0answers
38 views

Creating idiomatic and efficient method to stream large JSON file

The purpose of the code is to efficiently stream JSON items from a large file. I am wondering if this is efficient and decently idiomatic. Not sure how I could eliminate the while loop either. ...
4
votes
1answer
55 views

Analyzing spoke overlaps during rotation: Round 2

Round 1: Analyzing spoke overlaps during rotation I previously posted this question, but I've changed a lot of the code since then. There was a mention of the previous being a bit mixed up, and ...
6
votes
1answer
56 views

Analyzing spoke overlaps during rotation

For a personal project that I've recently started I have to analyze the rotation of two shapes with sets of spokes, where the spokes are evenly-spaced, and split into a given number. That is, if I ...
6
votes
1answer
73 views

Verifying that three cards make a “Set”

The game of Set involves cards with four properties: number, symbol, shading, and colour. Three cards make a "Set" if the property is either all the same or all different across the three cards, for ...
1
vote
0answers
33 views

Blockchain implementation in F#: Wallet

Introduction This is Part 3 of my F# blockchain implementation. Previous parts: Block and Blockchain Transactions Code In this part I am implementing a wallet functionality. The code is based on a ...
3
votes
2answers
425 views

Advent of Code 2018 day 1 part 2: find the first aggregated number that occures twice

I am using the coding puzzels of https://adventofcode.com for improving my F# skills. Problem: Day 1 Part 2: Starting with frequency 0, a list of numbers should be added successive generating new ...
8
votes
2answers
237 views

Conway's Game of Life F#

I am a C# developer learning F#. Would appreciate any suggestions on how this code can be improved. Main points I am interested in: Functional style of the code, absense of imperative style(C#) ...
1
vote
0answers
45 views

Blockchain implementation in F#: Transactions

Introduction This is Part 2 of my F# blockchain implementation. Previous parts: Block and Blockchain Code This time I am tackling transactions. The code is based on a JavaScript blockchain ...
2
votes
1answer
34 views

Connect elements of a list to elements of an other list using a two-dim array

Story: I build a kind of labyrinth. This labyrinth is divided in seven steps. You start with the first, then second, and so on to the seventh. You cannot go back to a previous step. Each step ...
3
votes
0answers
95 views

Creation of matrix with specific attempts at the end

What I want to do is build a Slay-the-Spire-like Map. As you can see in the following image, the map is splitted in ISteps and ...
5
votes
2answers
93 views

Encoding and decoding log entries in a Lossy Binary Format

One of the projects I'm working on requires logging a huge amount of information (basically, every function call). The problem is obviously that logging a lot of information has a few side-effects, ...
6
votes
1answer
197 views

Blockchain implementation in F#: Block and Blockchain

Some time ago I started writing a blockchain implementation for learning purposes. I used this article as reference. Originally I wrote the code in C# but recently I have rewritten everything to F#. ...
2
votes
0answers
87 views

Lexer function to handle the '/' character

I'm writing a toy compiler, which is in a very early stage of development. The lexer contains the following block of code: ...
2
votes
2answers
104 views

Sorting a list into different bags according to predicate

I've just started with F# (I'm coming from a mostly OO background) and I'm looking for feedback on the code, particularly: is this the way F# code should be written like? have I overlooked an ...
4
votes
1answer
87 views

F# Idiomatic Log4Net Wrapper

I put together a log4net wrapper that more closely resembles F#-idiomatic logging functions. The basic idea is that there's a Log module that defines a set of 8 ...
2
votes
1answer
158 views

Roslyn analyzer, converted from C# to F#

I'm learning F# and for an exercise, I took a roslyn analyzer in C# and ported it to F#. In the excerpt below the GetParameterInfo function: takes in ...
4
votes
1answer
78 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
160 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 ...
5
votes
3answers
374 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
58 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
134 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
53 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 ...
5
votes
0answers
285 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
87 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 ...
7
votes
0answers
87 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
99 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
193 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
53 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
62 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
83 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
213 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
82 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 ...
1
vote
0answers
37 views

HTTP request call for a token

The following code seems to have several redundant Flush, Close and Abort statements despite ...
2
votes
3answers
90 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
111 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
122 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
47 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
267 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
76 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
322 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
58 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 ...
5
votes
2answers
207 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
127 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
80 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
149 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 ...