Questions tagged [f#]

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

Filter by
Sorted by
Tagged with
25 votes
2 answers
2k views

First real-world F# application - how "good"/idiomatic is it? (long!)

After reading/watching various introductions and blog posts and some code here and there, doing a bit of the Try F# tutorial and starting to read "Real World Functional Programming", I felt I should ...
user avatar
16 votes
0 answers
184 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
15 votes
4 answers
940 views

Project Euler 6: Difference between sum of squares and square of sum

I've created a (very) simple solution for Project Euler problem 6: Project Euler Problem 6: Sum square difference The sum of the squares of the first ten natural numbers is, $$ 1^2 + 2^2 +...
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
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
13 votes
3 answers
1k views

Poker Hands Kata in F#

I'm a F# newbie, and would like to share my implementation of the Poker Hands Kata problem to get some feedback. ...
user avatar
12 votes
2 answers
10k views

Reading input from console in F# (as a sequence of lines)

Consuming input line-by-line until the end is often useful. In C# I would write the following loop: while ((line = Console.ReadLine()) != null) { // ... I ...
user avatar
  • 559
11 votes
1 answer
479 views

American Checkers

I am implementing the logic for a Checkers game in F#. I am writing my code in a library so it can be called from any UI provider, and am trying to do it in good FP style. I currently have the ...
user avatar
11 votes
1 answer
416 views

Ugly Numbers: A Rags-to-Riches Story

I stumbled upon an unaswered question, which looked like a good fit for a functional programming language. Here is the problem statement from codeeval: UGLY NUMBERS CHALLENGE DESCRIPTION: ...
user avatar
  • 16.1k
11 votes
1 answer
912 views

Approach to programmatically building hierarchical GUI components

At work I am developing an application using hand-coded Swing, and I've found that I have an easier time reading, writing, and maintaining hierarchical component creation using code blocks like: <...
user avatar
10 votes
4 answers
5k views

Functional approach to splitting list into sub lists

Here is my functional approach to split a list into sub lists, each having non-decreasing numbers, so the input \$[1; 2; 3; 2; 4; 1; 5;]\$ computes to \$[[1; 2; 3]; [2; 4]; [1; 5]]\$ The code ...
user avatar
  • 205
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
10 votes
1 answer
527 views

Getting the last date where a given week day occurred

I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me. In one of my pet projects I'm dealing ...
user avatar
  • 335
10 votes
2 answers
239 views

Is this Bridges code F# idiomatic?

Introduction I'm primarily a C# programmer, just starting out with learning F#. I found myself with a problem which felt like it was appropriate for a functional language, and now that I have the ...
user avatar
  • 5,714
10 votes
2 answers
362 views

F#zzBuzz: Learning the easy way

So I made a quick programme in F# to do FizzBuzz, I'm trying to learn more languages, so I figured I'd do something functional for a change. (Haskell is also on the list.) FizzBuzz is pretty self-...
user avatar
10 votes
3 answers
171 views

Generating image gauges from a value, min and max

One of the things I was recently investigating was the ability to generate "gauge" charts—that is, a chart which shows where a value stands within a range of values. As an example, if we know ...
user avatar
10 votes
1 answer
953 views

Small game written in F#

I'm trying to wrap my head around F#. I'd like your honest opinion about this simple game source code that I wrote. Rules are simple: Every player has soldiers and territory Player can recruit ...
user avatar
  • 203
10 votes
2 answers
685 views

American Checkers with AI

This is the third question in the series. Number 1 had most of the official two-player rules implemented, and Number 2 was the basic UI. This one has the complete two-player rules implemented, an AI ...
user avatar
10 votes
2 answers
230 views

F# inventory system - Part 2

I've refactored my previous inventory system, and added a few features like removing items from the Inventory class, easily obtaining the current selected item ...
user avatar
9 votes
1 answer
4k views

Reading input from the console in F#

In the process of learning F#, I wrote this code that reads lines of input from the console and stores them in a list. As far as I can tell the code works correctly, but since I'm new to functional ...
user avatar
  • 93
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
9 votes
1 answer
742 views

Prime factorization in F#

In the pursuit of learning F#, I have been working through some Project Euler problems. This is my solution for problem 3: ...
user avatar
9 votes
2 answers
1k views

Hierarchical State Machine in F#

I appreciate any feedback on where I might alter or improve my code for this project. This is an old attempt at implementing a Hierarchical State Machine in F#. I'm from a C#/OO background mostly. <...
user avatar
9 votes
1 answer
725 views

Deleting from Red Black Tree in F#

Yes I'm very slowly making my way through Purely Functional Data Structures. So I went through the section on Red Black Trees. What he presents is amazingly concise, except for the fact that he didn't ...
user avatar
9 votes
1 answer
309 views

Brainfuck interpreter in F#

I have some concerns, like the updateValue function. I was trying to follow the functional paradigm, but I wonder if I could use another approach or something. My ...
user avatar
  • 582
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
8 votes
2 answers
1k views

Mock/Stub out filesystem in F# for unit testing

I'm looking to do some basic verification testing on my functions that write to the filesystem. I took a hint from here on how to mock out the filesystem using an interface, but I'm kinda bummed on ...
user avatar
  • 183
8 votes
2 answers
132 views

Wordpress RSS Parser

Follow Up to my earlier question. This is an RSS Parser intended only to parse the feed Wordpress provides (and even then, only what I actually want to display on my website). ...
user avatar
  • 30.7k
8 votes
1 answer
1k views

Generic build script using Fake

I have something like a generic build script for a group of projects. I am using Fake but my F# skills are pretty bad. Would you please take a look and point where I can improve it? ORIGINAL ...
user avatar
  • 185
8 votes
1 answer
513 views

F# Either computation expression with while loop

I want to implement an Either computation expression in F#. The computation executes a function inside a while loop, and this function's return type is ...
user avatar
8 votes
1 answer
934 views

Simple RabbitMQ client wrapper

After reading this question, I've realized that I can do a lot to improve the quality of my question, so I've edited this question quite a bit. I've been teaching myself F# in my spare time off and ...
user avatar
  • 220
8 votes
1 answer
1k views

Discriminated-unions in C#

So I really want to have something similar to discriminated unions in C#. One way to do it is to use a visitor pattern, but it takes half a life to write all broilerplate code by hands. There is ...
user avatar
8 votes
2 answers
295 views

Conway's Game of Life F#

I am a C# developer learning F#. Would appreciate any suggestions on how this code can be improved. Main points I am interested in: Functional style of the code, absense of imperative style(C#) ...
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
7 votes
3 answers
348 views

Call an F# function with its previous result until the output no longer changes

Basically I have a function of the type 'a -> 'a (an optimization function on a AST) and I want to call it (passing the previous result) until it returns the ...
user avatar
7 votes
3 answers
1k views

Splitting a sequence into equal segments

I need to split up a sequence into equal segments of a given size (yes, the last one may be shorter), and I'm trying to find an efficient and idiomatic way to do it. I have two versions of the ...
user avatar
7 votes
3 answers
349 views

Functional Programming style in F#

I'm normally a C# developer, but I've started to learn F# and I want to make sure I'm writing code in a functional way that suits the language. I've quickly pieced this together with my knowledge from ...
user avatar
  • 173
7 votes
1 answer
973 views

Map implementation in F#

Just as a refresher I put together a simple Map implementation and I would love to get some feedback on it. ...
user avatar
  • 1,743
7 votes
2 answers
680 views

Caesar cipher in F#

I'm trying to broaden my horizon by learning functional programming (coming from OO, specficially C#). For this, I'm implementing some small problems to get a feeling for the language. One of my first ...
user avatar
  • 478
7 votes
1 answer
563 views

F# inventory system

To learn F#, I've implemented this very simple inventory system. While I'm proud that that it's my first program, and that it works, there are still a few areas that I'd like tips on, namely these: I ...
user avatar
7 votes
1 answer
213 views

Small console app to execute some remote scripts

I'm learning F# and functional programming, from a background in C# and imperative/OOP. I've ported a small, one-off console app from C# to F#. The port worked (the app behaves the same way), but I'd ...
user avatar
  • 211
7 votes
1 answer
1k views

F# Djikstras shortest path implementation

I'm just getting my feet wet with F#, by implementing some simple algorithms. First up: Djikstras shortest path. There is one piece I've written in this code which confuses me as to why it works: the ...
user avatar
  • 447
7 votes
1 answer
157 views

Refactoring of two command handler implementations with F# in the context of event sourcing

I've written some F# code to handle commands in the context of event sourcing which works along the lines below: Read Events from a specific event store stream Build the current state in the given ...
user avatar
  • 1,101
7 votes
1 answer
118 views

World's worst Christmas tree

Inspired by this question, I decided to grow my own fractal tree. The problem is: given an integer \$n\$, \$0 \leq n \leq 5\$, print the \$n\$th iteration of the fractal tree. The tree is probably ...
user avatar
  • 16.1k
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
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
7 votes
1 answer
560 views

Efficient generic type conversion between numeric types in F#

It's easy to write a function that adds two ints in F#: let add x y = x + y Actually, it's the same as: ...
user avatar
7 votes
0 answers
113 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
497 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
6 votes
3 answers
483 views

Is there any way to improve (shorten) this F# code?

I have a very good grasp of the syntax and features of F# as well as some of the concepts that mesh well with the language. However, I do not have enough experience writing it to feel comfortable that ...
user avatar

1
2 3 4 5
8