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
3answers
95 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
120 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
125 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
296 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
90 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
374 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
67 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
281 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
147 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
83 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 ...
1
vote
0answers
45 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
89 views

F# Finding the powerset of a set

I have this function which takes a list as input and computes the powerset. ...
5
votes
1answer
149 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
417 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
69 views

F# functions implementing polynomial arithmetic [closed]

I have a couple of functions for doing basic arithmetic on polynomials. ...
3
votes
1answer
73 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
482 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
129 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
117 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
166 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
103 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
177 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
48 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
132 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
42 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. ...
4
votes
1answer
234 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
550 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
69 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
86 views

Learning F# with Prime Factorization

In my quest to learn F#, I implemented Prime Factorization. First, the code: ...
5
votes
2answers
222 views

Immuitable recursive linear search of an array of string

I am new to F#. Is the following code, which represents about three hours of work, a canonical way to achieve its goals. If not, how can it be improved? For instance, can we provide a default value ...
7
votes
2answers
474 views

Caesar cipher in F#

I'm trying to broaden my horizon by learning functional programming (coming from OO, specficially C#). For this, I'm implementing some small problems to get a feeling for the language. One of my first ...
4
votes
1answer
69 views

Calculator for magic item creation in RPG

I have created a simple calculator that will assist in creating magic items from the tabletop RPG Pathfinder. Here are the full requirements, and if you want a more concise version, here is a player ...
3
votes
1answer
145 views

Parsing command line arguments

Usage: ...
4
votes
1answer
185 views

Searching files in directory with various filters

Requirements Note: the requirements are invented by me for practicing functional programming. Functional Requirements Given a directory, all files below the directory (and its sub directories) ...
1
vote
1answer
518 views

F# binary reader

I've written a fairly simple script in F# which reads structured data from binary. I've avoided using the built-in .NET BinaryReader class because it's stateful in that it maintains its index in the ...
6
votes
1answer
109 views

Reading numbers from console until input isn't a number

I want to read N numbers (Nmax = 100) from console into a list. N is not known, but the first input that is not a number may break the reading process... However the solution should be as simple as ...
4
votes
2answers
611 views

Event sourcing using functional programming

Is this a satisfactory implementation of event sourcing using functional programming? ...
3
votes
2answers
186 views

Compact game of life implementation

I am learning F# and implemented Conway's Game of Life as an exercise (There are also other implementations on CodeReview). I have tried to forget all my object-oriented background and practice "...
1
vote
0answers
133 views

Simple INI and command-line parsing, functional programming edition

I'm in the beginning stages of rewriting the model layer of my VBA Sync Tool in F#, to better learn functional programming. So far I've defined: A public ...
6
votes
0answers
316 views

A* Algorithm in F#

Inspired by this post I looked up A* on wikipedia and went on with my own implementation as seen below where I try to mimic the pseudocode on Wikipedia but in a recursive manner. I would like any ...
4
votes
1answer
106 views

Pool Checkers with AI

I recently added Pool Checkers to my Checkers game. My main concerns are about how I manage calling the correct variant in my PublicAPI functions. Because this is ...
3
votes
0answers
99 views

F# implementation of the A* algorithm round 2

This is my second attempt at implementing the A* algorithm using F#, the first one is here. What I changed: I removed the Node class and added two records named ...
3
votes
1answer
167 views

F# implementation of the A* algorithm

This is my first attempt at writing something useful in F# and in a functional way in general. I would appreciate if you could point out any issue, even details, as I'd like to put all the bad habits ...
0
votes
1answer
147 views

Adding jokers to a deck of cards

I originally had the following code: ...
3
votes
3answers
125 views

F# program to generate a Map of substrings frequencies

I wrote the following F# program that takes an input txt file and create a Map that contains all possible substrings of size N and their frequency in the file. In other words if I call the program ...
5
votes
1answer
116 views

Compute a value (and update a CSV record), based on prior value

The F# code below embodies the two specific questions I have. It is part of a working transformation utility, the entirety of which, including sample data, is in this gist: http://bit.ly/2i3kUwF. ...
10
votes
2answers
458 views

American Checkers with AI

This is the third question in the series. Number 1 had most of the official two-player rules implemented, and Number 2 was the basic UI. This one has the complete two-player rules implemented, an AI ...
6
votes
2answers
230 views

Navigating a bounded 2D list (Advent of Code, Day 2: “Bathroom Security”)

I'm trying to solve the following Advent of Code problem in F# for practice. Description of problem (can be found here): Basically, there's a 'key pad' that I need to figure the combination to. To ...