Questions tagged [f#]
F# is a succinct, expressive, and efficient functional and object-oriented language for .NET
47
questions with no upvoted or accepted answers
16
votes
0
answers
188
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 ...
7
votes
0
answers
116
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 ...
7
votes
0
answers
522
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 ...
5
votes
0
answers
375
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
0
answers
491
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 ...
4
votes
0
answers
368
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 ...
4
votes
0
answers
90
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 ...
4
votes
0
answers
255
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, ...
4
votes
0
answers
334
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 ...
3
votes
0
answers
224
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 ...
3
votes
0
answers
159
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:
...
3
votes
0
answers
95
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 ...
3
votes
0
answers
184
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 ...
3
votes
0
answers
230
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 ...
3
votes
0
answers
177
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, ...
3
votes
0
answers
111
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 ...
3
votes
0
answers
187
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 ...
3
votes
0
answers
114
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 ...
3
votes
0
answers
115
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
0
answers
61
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:
...
3
votes
0
answers
153
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:
...
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?
...
3
votes
0
answers
64
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 ...
2
votes
0
answers
94
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 ...
2
votes
0
answers
87
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 ...
2
votes
0
answers
49
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.
...
2
votes
0
answers
148
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
0
answers
99
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 ...
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 ...
2
votes
0
answers
92
views
Blocking Memory Queue
This is a FIFO blocking memory queue in F# to be used as a component in a logging library.
...
2
votes
0
answers
196
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 ...
2
votes
0
answers
347
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 ...
1
vote
0
answers
78
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, ...
1
vote
0
answers
144
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 ...
1
vote
0
answers
46
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.
...
1
vote
0
answers
76
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:
...
1
vote
0
answers
54
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 ...
1
vote
0
answers
121
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 ...
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 ...
1
vote
0
answers
123
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 ...
1
vote
0
answers
199
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
0
answers
159
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 ...
1
vote
0
answers
60
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
0
answers
116
views
F# Finding the powerset of a set
I have this function which takes a list as input and computes the powerset.
...
1
vote
0
answers
230
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 ...
1
vote
0
answers
157
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 ...
1
vote
0
answers
268
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. ...