Questions tagged [f#]
F# is a succinct, expressive, and efficient functional and object-oriented language for .NET
35
questions with no upvoted or accepted answers
16
votes
0
answers
190
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
539
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
388
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
502
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
412
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
93
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
263
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
336
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
250
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
166
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
122
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
208
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
256
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
190
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
112
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
191
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
117
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
117
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
154
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
65
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
117
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
88
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
51
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
158
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
106
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
64
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
94
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
204
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
352
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
96
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
163
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
86
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:
...