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
Filter by
Sorted by
Tagged with
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 ...
Morten Christiansen's user avatar
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 ...
Aaron M. Eshbach's user avatar
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 ...
user avatar
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 ...
Maxime Recuerda's user avatar
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 ...
Colonel Panic's user avatar
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 ...
Natalie Perret's user avatar
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 ...
David Faivre's user avatar
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, ...
TeaDrivenDev's user avatar
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 ...
Veksi's user avatar
  • 431
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 ...
Adam Hodgson's user avatar
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: ...
user avatar
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 ...
Aaron M. Eshbach's user avatar
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 ...
user avatar
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 ...
user avatar
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, ...
Natalie Perret's user avatar
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 ...
Henrik's user avatar
  • 81
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 ...
cmeeren's user avatar
  • 185
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 ...
HMR's user avatar
  • 139
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 ...
Stud's user avatar
  • 786
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: ...
Jon's user avatar
  • 163
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: ...
robkuz's user avatar
  • 129
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? ...
user1206480's user avatar
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 ...
user1206480's user avatar
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 ...
David Hayes's user avatar
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 ...
user avatar
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. ...
Maslow's user avatar
  • 283
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: ...
Myk's user avatar
  • 141
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 ...
Aaron M. Eshbach's user avatar
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 ...
Bruno Costa's user avatar
  • 5,566
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. ...
Lord Terabyte's user avatar
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 ...
Henrik's user avatar
  • 81
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 ...
Veksi's user avatar
  • 431
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, ...
DaemonFire's user avatar
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 ...
Harshal Patil's user avatar
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: ...
Wojciech Szabowicz's user avatar