Questions tagged [f#]

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

50 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
16 votes
0 answers
183 views

Encoding the problem domain of products and prices into the typesystem in F#

I'm trying to design a model for purchasing amounts of products in F#, following the ideas for designing for correctness (source). The idea is to use the type system to capture the different legal ...
user avatar
7 votes
0 answers
112 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 ...
user avatar
7 votes
0 answers
492 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 ...
user avatar
5 votes
0 answers
356 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 ...
user avatar
5 votes
0 answers
464 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 ...
user avatar
4 votes
0 answers
318 views

F# XML Generation in .NET Core: XmlSerializer or XmlProvider

I am working on SEPA XML generator in F#. I developed two solutions that are roughly equivalent, one relies on the XmlSerializer while the other relies on ...
user avatar
  • 1,101
4 votes
0 answers
83 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 ...
user avatar
4 votes
0 answers
252 views

Aggregation of values over a hierarchy

I have a number of objects of a type Workplace that exist in a hierarchy that is given by some properties (Department, ...
user avatar
4 votes
0 answers
332 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 ...
user avatar
  • 431
3 votes
0 answers
179 views

Command line wordle

I am seeking a review of my command line wordle game. Having only recently started exploring functional programming, I expect that there will be no shortage of areas to improve. This is my first ...
user avatar
3 votes
0 answers
148 views

N-Queens Puzzle

The N-Queens puzzle can be solved in many ways. One is by a depth-first-search backtracking algorithm. Below is my generalized version using mutual recursion: ...
user avatar
3 votes
0 answers
72 views

Functional Dependency Injection Abstraction

The F# web-development framework Giraffe supports a functional style of Dependency Injection using a form of the Reader monad, as explained in this GitBook. I would like to use this pattern more ...
user avatar
3 votes
0 answers
166 views

Flashcard Website

In my endeavor to learn Angular, I've created a flashcard site with an F#/Mongo backend. As I'm new to Angular, I'm going to post everything; any and all feedback is welcome. First, some pictures of ...
user avatar
3 votes
0 answers
208 views

Async in Railway Oriented Programming in F#

In F# the Railway Oriented Programming pattern can be implemented synchronously using the Result<'t,'terr> type as result value for functions, so they can be ...
user avatar
3 votes
0 answers
159 views

A simple functional F# wrapper for EasyNetQ

This is my first attempt at creating a small module to wrap the .NET library EasyNetQ in F# to make it more functional. I am pretty new to F# and I would like to get feedbacks on everything: types, ...
user avatar
  • 1,101
3 votes
0 answers
108 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 ...
user avatar
  • 81
3 votes
0 answers
175 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 ...
user avatar
  • 185
3 votes
0 answers
113 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 ...
user avatar
  • 139
3 votes
0 answers
109 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 ...
user avatar
  • 786
3 votes
0 answers
59 views

SqlDataConnection update method

I'm using Microsoft's SqlDataConnection type provider. However, the only way I've seen to update a row in the database is to use something similar to this where it updates mutable values: ...
user avatar
  • 163
3 votes
0 answers
152 views

DSL design for iOS Autolayout

I am building a small DSL for iOS' autolayout feature. Obviously I want to have a typesafe way to define autolayouts instead of doing VSL. I came up with the following: ...
user avatar
  • 155
3 votes
0 answers
57 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? ...
user avatar
3 votes
0 answers
63 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 ...
user avatar
2 votes
0 answers
70 views

Download and parse XML data from a URL every minute with F#

The purpose This code is intended to achieve the following goals:- Create a hard coded list of lifts, this is pretty static and I add some extra info so I'm ok with this being in the code but I may ...
user avatar
2 votes
0 answers
82 views

Sanitize input for a "robot on a grid" kata

I have the following piece of code which is FSI tested and works. However, I want to trim it as much as possible (not only the comments, which are there for my own future reference) and make it as ...
user avatar
2 votes
0 answers
47 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. ...
user avatar
  • 293
2 votes
0 answers
141 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: ...
user avatar
  • 141
2 votes
0 answers
93 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 ...
user avatar
2 votes
0 answers
62 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 ...
user avatar
  • 5,561
2 votes
0 answers
89 views

Blocking Memory Queue

This is a FIFO blocking memory queue in F# to be used as a component in a logging library. ...
user avatar
2 votes
0 answers
190 views

AES256 + HMACSHA256 'secretbox'

I aim to create a few primitives for creating AES256-then-HMACSHA256 secured session state through cookies. What I've considered: HMAC instead of plain sha to avoid hash extension attacks input ...
user avatar
  • 81
2 votes
0 answers
340 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 ...
user avatar
  • 431
1 vote
0 answers
47 views

F# thumbnail Scraper

Thumbnail Scraper I'm a C# programmer learning F#. For my first program I created a console youtube thumbnail scraper. It parses command line arguments with argu and then downloads the thumbnails, ...
user avatar
1 vote
0 answers
120 views

How to flatten the nested try-catch block in F#?

How to flatten the nested try-catch block in F# for the following code? I am using EF Core with F#. The nested is required because I need to Rollback the transaction if there are errors in saving or ...
user avatar
1 vote
0 answers
44 views

Photo rename by Exif date and group into folders with a threshold

I wrote this tiny F# project yesterday, but I am a bit rusty and I would like to know if there is anything I can refactor and make more elegant. ...
user avatar
1 vote
0 answers
68 views

F#, Timer and propperly removed ElapsedEventHandler

I have a simple method that receives messages from bus, builds response and send it back, and it looks like: ...
user avatar
1 vote
0 answers
50 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 ...
user avatar
  • 354
1 vote
0 answers
114 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 ...
user avatar
  • 354
1 vote
0 answers
39 views

HTTP request call for a token

The following code seems to have several redundant Flush, Close and Abort statements despite ...
user avatar
  • 201
1 vote
0 answers
118 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 ...
user avatar
1 vote
0 answers
196 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 ...
user avatar
1 vote
0 answers
136 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 ...
user avatar
  • 111
1 vote
0 answers
54 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 ...
user avatar
1 vote
0 answers
110 views

F# Finding the powerset of a set

I have this function which takes a list as input and computes the powerset. ...
user avatar
1 vote
0 answers
224 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 ...
user avatar
1 vote
0 answers
150 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 ...
user avatar
  • 203
1 vote
0 answers
130 views

MailboxProcessor and prioritized messages

I'm trying to create an agent that holds on to Data and does further work with it upon receiving the Work message. ...
user avatar
  • 111
1 vote
0 answers
137 views

Boiler-plate reduction or elimination layer for System.Data .net 4.0

I'd really like to get this to be as clean as possible such that the C# access to it looks succinct. To that end, I've made C# helper methods that abstract out things like ...
user avatar
  • 293
0 votes
0 answers
53 views

Early exist fold implementations in F# with a high degree of similarity

I've been writing a bunch of helper functions lately, all revolving around the concept of an early exit fold (which is a bit like unfold, i.e. you can control when the looping ends but you pass a list ...
user avatar
  • 1,101
0 votes
0 answers
86 views

Project Euler 1, 2 and 3: Functional Programming style using F#

After doing about 50 Project Euler problems in my "native" language (C#) I decided to redo some of the problems I did many years ago in F#, as it's a language I always want to give a go. ...
user avatar