Questions tagged [f#]

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

Filter by
Sorted by
Tagged with
3 votes
2 answers
132 views

Printing a table

I have this recursive function that I made which prints a table, but I really think my current solution is really ugly. Does anyone have an idea as to how I can improve my solution? I'm trying to ...
user avatar
  • 31
1 vote
2 answers
784 views

F# Insertion sort

I made a simple insertion sort in F#, it uses a tail recursive shift function that attempts to shift an element in a list until it is in the right order. Would like ...
user avatar
7 votes
3 answers
167 views

Doing an ROP style bind for two functions on the same input in a pipeline

I am working on understanding Railway Oriented Programming (Scott Wlaschin style) in F#. In my example I want to create a pipeline which does some calculation, applies two different functions to the ...
user avatar
  • 267
4 votes
2 answers
42 views

Implement total savings function on a record type

the TotalSavings() function on the record below has a code smell that I can't exactly detail. Is there a more readable alternative for implementing this function on a record type? ...
user avatar
7 votes
1 answer
103 views

Streaming a Pin functionally(ish)

Earlier today I wrote a question (Validating a StreamingPin) and I thought it was a good idea (apparently I was the only one who thought so, but whatever), so I proceeded further with it and developed ...
user avatar
14 votes
1 answer
509 views

Grand Chess domain model and helper functions

So I am trying to write, essentially from a blank slate, a program that plays Grand Chess. In short, it is a chess variant that is played with two extra pieces, on a 10x10 board, no castling, and ...
user avatar
  • 897
5 votes
1 answer
2k views

Battleship Game

Inspired by this question, I went on with the following version. My goal was to focus on pure functions, to avoid mutable variables and to be strictly functional. I have ignored the computer player ...
user avatar
3 votes
1 answer
221 views

hl7 parser with fparsec

I have a little experience working with .hl7 data (format for transmitting health data), so I decided to try and write an .hl7 parser using fparsec. A standard .hl7 segment is a single line with: ...
user avatar
10 votes
2 answers
365 views

You can't sink me

Here is a Battlehips game in F#. Now, before you start jumping up and down on my code, please understand that, for all its awesomeness, F# has a serious limitation: Its compilation is linear, and the ...
user avatar
4 votes
1 answer
456 views

Directory listing, sorting and filtering in F#

Here is my first try at F#. My only functional experience is from JS. This program takes a path as an argument and presents the user with numbered subdirs in that path. The user then selects one of ...
user avatar
13 votes
3 answers
927 views

Return total balance from unsorted purchase items that may have specials

This is in reference to the following kata: ...
user avatar
3 votes
1 answer
246 views

F# Simple Tree evaluation

I'm currently trying to learn the idiomatic way to write F# code. The code simulates a basic calculator with only binary plus, minus and unary minus. I'd like to know if there is a better way to ...
user avatar
  • 95
5 votes
1 answer
161 views

Unit test for allowable checkers moves

Is pattern matching within a unit test a code smell? Do I really need to throw an exception just for my test to fail if the function under test receives invalid arguments (i.e. not Succeeded case ...
user avatar
1 vote
1 answer
177 views

Idiomatic F# unit test using xunit and unquote

I'm writing some unit tests for testing C# code but I'm using F# and Unquote for the first time for the unit tests and would like some input as to how I might make the tests more 'f-sharpier' to take ...
user avatar
5 votes
2 answers
143 views

Checkers moves using union types

How do I refactor common code with different union types? I'm still struggling with refactoring F# code with different types but same behavior. I have the following function that I would like to ...
user avatar
7 votes
1 answer
200 views

TCPListener server to discover clients on a network

I am currently writing a program to sync files (music, photos, etc) from my PC to an Android device. In order to do this, I have 2 application: one that is running on my PC, and one that shall be ...
user avatar
  • 173
4 votes
1 answer
157 views

Card combination finder in F#

I have been adding and tinkering a bit with the code from my Baloot tally finder. I updated the code a bit and factored a new things, but for this post I am trying different stuff: to detect whether ...
user avatar
  • 897
4 votes
1 answer
88 views

Async.sequence implementation

I have a simple implementation for "Async.sequence" (the name came from here), but I would like someone to review it for performance, tail call optimization, and ...
user avatar
4 votes
1 answer
762 views

Recursively traverse directory tree and print all files

I want to build a small console program, that for given directory, will print (for now) all files inside that tree. Here is an F# script that I came up with: ...
user avatar
3 votes
2 answers
158 views

F# function to concatenate some DSL scripts with indentation

I'm rather new to F# and functional programming. I wrote the following method to concatenate some custom dsl scripts. The function works are expected without errors. I wanted to know if there was a ...
user avatar
  • 139
5 votes
2 answers
947 views

Recursive implementation of a zip function in F#

I'm learning F# from Tomas Petricek's "Real-World Functional Programming" book. As suggested at one point in the book, I started implementing a zip function using a ...
user avatar
5 votes
1 answer
140 views

Tally Calculator for Baloot in F#

This is a tally calculator for the Saudi card game Baloot. As in, they're a set of functions so that the user would provide their winnings at the end of a round (card captured, projects declared, etc) ...
user avatar
  • 897
3 votes
1 answer
85 views

Divide number by factors

I'm learning F#. The code below gets a number e.g. 100 and list of factors and should divide that number by the factors without any rest. (There is an actual code I've got in C#, but this is F# port). ...
user avatar
1 vote
1 answer
235 views

K-Means Clustering - F# Learning Challenge

Inspired by this blog I went on implementing my own version as a F# learning challenge. It turned out to be quite different than the original (but somewhat faster for large samples). The first code ...
user avatar
2 votes
1 answer
73 views

IsImageUrl extension method written in F#

I'm a newbie to F# and so I've written a small extension method library to practice the language. The extension method attempts to determine if a url string is for an image. I wrote the code as an ...
user avatar
8 votes
4 answers
7k views

Swap even/odd characters

I wrote some code to solve this problem https://www.hackerrank.com/challenges/string-o-permute which basically states: take an even length string and swap all the even indexed characters. For example ...
user avatar
4 votes
1 answer
273 views

Get a stock quote from a web page using F#

I want to extract a price for a single index fund, the price of which is available on dynamic web pages. Being new to this, my original idea was to download the single page of static HTML and get ...
user avatar
4 votes
2 answers
1k views

Web crawler in F#

I have been writing a web crawler in F# that downloads pages with stylesheets and scripts. Can somebody give me suggestions on improving this code, please? Would appreciate any feedback that could ...
user avatar
  • 41
2 votes
1 answer
215 views

NFA and DFA implementation

Can you review my F# code and point out some insights about it? What I want to know, in order of relevance: Avoid so much common code between DFA and NFA. I want to make something more generic, ...
user avatar
  • 993
2 votes
1 answer
422 views

Transforming XML to HTML with XSLT

I'm still learning from designing with types non strings by Scott Wlaschin. For my project I transform some XML to HTML with xslt. Because every filename can have side effects, they are stored in ...
user avatar
5 votes
1 answer
288 views

My Brainfuck interpreter in F#

I'm very new to functional world. I've written a simple brainfuck interpreter as my first F# program. What I would like to know: Am I using the right data structure for each situation? Is my code ...
user avatar
  • 993
3 votes
1 answer
62 views

Compare performance of simple addition on one to many cores

I read recently that ENIAC originally was capable of 5000 additions per second. Naturally, I had to test my own laptop's capabilities and this became an instructive experiment in F#, which I suck at. ...
user avatar
6 votes
2 answers
936 views

Console input prompt loop in F#

I'm learning F#, starting with baby steps. Is there a way to write this code in a more succint way, while keeping the same semantics? Maybe by using a Seq or ...
user avatar
  • 205
1 vote
1 answer
405 views

Parsing .PLY file using F#

I'm fairly new to F# and have written a program to parse PLY files - this is however done in an imperative way with mutable values and as far as I know that should be avoided in functional languages. ...
user avatar
  • 113
4 votes
2 answers
71 views

Breaking lists into subgroups in F#

I'm starting to play with F# to do some data parsing and I was able to create a function to group an array of string into sub groups. The code looks like this: ...
user avatar
  • 335
5 votes
1 answer
639 views

Anagram finder in F#

I've been learning F# for a month or so and I'm wondering how good my "functional" aspect of coding is. When I first started, I did this using an iterative approach with a lot of <- and mutables ...
user avatar
  • 205
3 votes
0 answers
60 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
2 answers
246 views

Heightmap generation using midpoint displacement

I am writing a program to generate a height map following the midpoint displacement algorithm (somewhat similar to diamond-square). I'm at the point where I have a recursive program that paints the ...
user avatar
  • 347
2 votes
0 answers
90 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
9 votes
2 answers
237 views

Unit testing F# code without using an existing test library (MSTest, xUnit, etc.)

I know I can probably use MSTest (I'm under Linux without an IDE so maybe not?) or another unit testing library, but for a small project I decided to write my own unit tests without resorting to a ...
user avatar
  • 347
0 votes
1 answer
130 views

Converting height map bitmap to json

This is my first F# program. It's a command line utility that takes a parameter containing a path to an height map bitmap and prints out this height map converted to JSON format. ...
user avatar
  • 347
4 votes
1 answer
322 views

FizzBuzzWoof in F#

I'm learning F#, and have challenged myself to write a good functional implementation of FizzBuzzWoof. (The difference from "standard" FizzBuzz is that any number that either is divisible by or ...
user avatar
  • 143
4 votes
2 answers
1k views

Dijkstra algorithm implementation in F#

I'm trying to implement Dijkstra algorithm in F# for finding the shortest path in a undirected tree using a heap. I've used the type PriorityQueue found here and the code can be found here. ...
user avatar
3 votes
1 answer
327 views

F# cache manager

This is a port of a C# cache manager we use to F#. This is my first F# code, and I've tried to make it as idiomatic as possible. I would appreciate input on style, performance considerations,...
user avatar
  • 131
3 votes
1 answer
359 views

Factory pattern in F# for a web scraper

I'm trying to learn F# by creating a little web scraper that will do custom scraping based on the url domain. For this, I need to create and select the correct kind of scraper. I figure I would use a ...
user avatar
3 votes
1 answer
280 views

Project Euler Q7 - 10001st prime

The problem is (source)... By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10001st prime number? This is my second attempt at the ...
user avatar
1 vote
1 answer
44 views

Create a collection of binaries with random set positions

I would like to create a collection of binaries with n set bits and total length should be between n and 31; also those set bits ...
user avatar
2 votes
1 answer
46 views

Reordering a list from the ends towards the middle

...
user avatar
6 votes
1 answer
218 views

Project Euler Q2 - Sum of even Fibonacci numbers

I'm very new at F#, and am using Project Euler to help me learn. Question #2 kept me going for a while, as my initial attempt at an answer was very slow and inelegant. Then I learnt about Seq.unfold, ...
user avatar
5 votes
1 answer
105 views

Solution to Project Euler problem 5 (LCM of 1 to 20)

I'm an experienced C# developer trying to teach myself F#. I spent a day or 3 reading throught the F# wikibook trying to get to know the syntax and F# fundamentals. As an exercise I'm trying to go ...
user avatar
  • 153

1 2 3
4
5
8