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

learn more… | top users | synonyms

6
votes
1answer
68 views

Hello Functional World: Counting occurrences of each letter

Coming from a OO (C#) background, I am trying to learn some FP. To help me transition, I am trying to learn F#. I am taking baby steps. I set myself a simple challenge to count the instances of each ...
5
votes
2answers
52 views

Add two numbers stored as a list in F#

I am solving the following problem: You are given two lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the ...
6
votes
1answer
264 views

Game of life in F#

First attempt at doing anything F#-y from a very heavy C# background, think I've grasped the fundamentals of FP, but always good to get other eyes on it: ...
5
votes
2answers
302 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 ...
4
votes
2answers
58 views

Reverse Polish Notation in F#

In my question to learn F#, I've decided to get one step closer to creating a programming language, and implement this simple Reverse Polish Notation "interpreter" of sorts. It does not allow for ...
6
votes
0answers
90 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: ...
9
votes
2answers
91 views

Simple 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 ...
6
votes
1answer
362 views

Very simple 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: ...
5
votes
2answers
98 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 wanted to do ...
3
votes
1answer
90 views

Building and flattening a dependency graph

The Problem Given a list of dependencies ('a * 'a) list where the first item has a dependency on the second item, construct a dependency graph and then 'flatten' ...
3
votes
1answer
59 views

Projecting future positions

My code takes a starting position (which must be completed) and a list of updates (each element of which is optional). It then projects future positions, using the appropriate value from each update, ...
4
votes
1answer
120 views

Sudoku game logic

I am trying to create a Sudoku game in F# and I'm having a bit of trouble with the file reading and writing. But since I've also just started programming in f# I would like to check if my thinking is ...
0
votes
2answers
95 views

Extracting meta data from nupkg file with F# looks like C# Linq

The code snippet below examines a nuget package file (zip file with meta) and extracts all file names referenced inside. The final result should be a ...
1
vote
1answer
84 views

Saving an uploaded file and returning form data

I am new to F#. This code is basically a port I did from C#. I am sure there is room for a ton of improvement, so how can I improve and make this more efficient? ...
4
votes
0answers
182 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, ...
5
votes
1answer
93 views

Test file word cloud in F#

This code is meant to take in a command line argument and output a 'tag cloud'. It's more of an exercise in learning F# for me because this is my first non-tutorial code file. How could this code be ...
7
votes
1answer
111 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 ...
8
votes
1answer
183 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 ...
1
vote
2answers
44 views

Better yielding tuple-d union case values in list generation

I have a situation where I'm stitching three different unions into a triplet tuple for building a map/dictionary of strongly typed values keyed on a string. One of the union cases is very large, the ...
4
votes
1answer
116 views

Command Dispatcher for messaging using MailboxProcessor

This code is intended to process commands in a CQRS+Messaging system. It will parallelize the message processing to the degree you specify by the msgToIdFn ...
2
votes
1answer
85 views

Finding a customer's gender

I have been playing with Async/parallel execution in entity framework for while. I'm not sure if I'm doing it right. I have two entity contexts: one for reading and one for writing. The reading ...
2
votes
1answer
54 views

Extracting a maximum from zipped lists

I have code that zips 3 lists, finds a maximum and extracts part of the max tuple. Isn't there a shorter way to do this in F#? ...
1
vote
0answers
51 views

Boiler-plate reduction or elimination layer for System.Data .net 4.0

I'd really like to get this to be as clean as possible such that the C# access to it looks succinct. To that end, I've made C# helper methods that abstract out things like ...
5
votes
1answer
206 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 ...
3
votes
1answer
138 views

CRUD (database layer) for F# with TypeProviders

I am a newbie in F# and I am thinking about use F# in my next project. The project will work the database and I need to store and retrieve instances of objects in the Db. Could you please check my ...
2
votes
1answer
29 views

Structuring Test Data

I'm just getting started with F# and was writing some unit tests for some functionality I had written. In the interest of brevity, I decided to create some lists of the different test cases and just ...
5
votes
1answer
72 views

Lightweight TicTacToe in F#

This is more of a 'model' of TicTacToe, as you'll see it's not "gameified" in the sense that it will allow for inputs and outputs nor will it record any "active" state of the game but those things are ...
3
votes
2answers
162 views

Select some indexes in a list of lists

I have a record type which holds a list of table rows. Each row is also a list. The first row is assumed to be the header row. In addition the type optionally defines a filter - a list of columns (the ...
1
vote
2answers
123 views
3
votes
0answers
98 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
1answer
86 views

Decompose a value as a sum of square numbers

My daughter had a question on her maths homework which was to write a value as a sum of 4 or fewer square numbers. For example, x = 73 could be 36 + 36 + 1. I came up with a really brute force ...
1
vote
1answer
130 views

Ordering a sequence of objects

The below code takes an incoming sequence of objects, checks each object's type and then yields the object in a specific order. This is all taking place in an active pattern. As I am still new to ...
1
vote
0answers
35 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 ...
4
votes
1answer
101 views

Add spaces before uppercase letters

I'm trying to convert some very simple C# string utility functions to F# as a learning exercise. Ignore the fact that the C# version is implemented as an extension method for the moment. The ...
5
votes
0answers
79 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 ...
2
votes
1answer
101 views

Project Euler 3 in F#

I'm looking for some general feedback on my solution to Project Euler challenge 3 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? ...
2
votes
2answers
92 views

Project Euler #2 in F#

Project Euler Problem 2 asks for the sum of all even Fibonacci numbers below 4 million. My first attempt at this problem using functional programming with F#. I would've liked to use some kind of ...
4
votes
2answers
462 views

Project Euler Problem 1 - Functional approach?

I'm trying to learn F# right now coming from C# and I'm finding it a great difficulty to "reconfigure" my mind to the functional programming mindset. So I'm going to attempt a few Project Euler ...
10
votes
2answers
189 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 ...
2
votes
1answer
148 views

Simple actor system in F#

Any thoughts on my actor model here? Obviously it doesn't have implementation for concurrency as it stands- being completely synchronous, but it should be easy to make the send/become/create be sent ...
3
votes
2answers
262 views

Longest Common Subsequence and Longest Subsequence Palindrome

The following code computes: The longest common subsequence between two strings, where a subsequence of a sequence does not have to consist of contiguous elements of the sequence. The longest ...
5
votes
1answer
239 views

The Functional FizzBuzz Kata

I run a coding dojo at work. For one session I'm to showing that you can use a kata to get into a new language. I'm using the FizzBuzz Kata to to show F# (and JavaScript) because it is short. The ...
4
votes
2answers
192 views

Excel calculation engine

We have currently rewritten an Excel calculation engine in F# and are looking to refactor the code to make it a lot more idiomatic and standardised. One of the big problems with the code is that we ...
2
votes
2answers
138 views

Idiomatic and Conventional F#

As of late I have been learning F#. Today I accumulated what I have learned so far to develop my first program - a script that counts the number of lines of code in a given Visual Studio project. ...
1
vote
1answer
54 views

Searching for files across multiple code projects

I was tasked with conducting a large number of text searches in the code files of multiple projects. Initially, I just used the Find in Files feature of Visual Studio in a couple of the running ...
3
votes
2answers
279 views

Split string into parts of varying lengths

I need to split a string into parts of varying predefined lengths, given as a sequence of integers. After a first imperative attempt using a sequence expression and a reference cell, I have now come ...
5
votes
2answers
155 views

'Countdown' Numbers round - combine numbers arithmetically to reach a target

Countdown is a British gameshow where contestants compete in word and number challenges. During the numbers round, six numbers are chosen semi-randomly and the task is to combine them using addition, ...
4
votes
1answer
124 views

Detecting connected acyclic through Tarjan strongly connected components variant

I want to verify that a given directed graph is connected and acyclic (DAG). I have implemented a modification of the Tarjan's strongly connected components algorithm in imperative style (as the ...
4
votes
2answers
249 views

Detecting properly nested parenthesis using functional programming

So I have this code that is my attempt at a coding test from Codility. While my code produces correct results according to the requirements, (which unfortunately are copyrighted so I don't think I can ...
4
votes
1answer
230 views

Join() equivalent function for F# sequences

I am porting C# code to F# that makes use of LINQ's Join() extension method. Just as I use that in method call chains, I would of course like to have an F# function ...