You are here

F# Snippets

Subscribe to F# Snippets feed
Updated: 1 month 2 days ago

Tesco in 70 lines of code

Tue, 04/17/2012 - 04:16
Domain model for the Tesco checkout implemented in F# using discriminated unions (in 20 lines of code) and console-based user interface for scanning products and calculating the total price.
Categories: Communities

Building Strings

Sun, 04/15/2012 - 16:25
When sprintf and String.concat is either too slow or not really what is needed, one can use System.Text.StringBuilder. This snippet makes working with StringBuilder much more convenient and the resulting code more succint.
Categories: Communities

Expanding quotations

Sun, 04/15/2012 - 08:45
The snippet implements a function "expand" that takes a quotation and performs two operations. It replaces all calls to methods marked with ReflectedDefinition with the body of the method and it simplifies all expressions that can be reduced in call-by-name style (let binding & application of...
Categories: Communities

Monadic transactions for Clojure-style atoms

Thu, 04/12/2012 - 13:44
This is a simple implementation of a monadic transaction builder for Clojure-style atoms. Based on original code by Nick Palladinos.
Categories: Communities

Monotone Chain Convex Hull Algorithm

Sat, 04/07/2012 - 18:50
Andrew's Monotone Chain Convex Hull algorithm: given points in 2 dimensions, determine their convex hull by constructing the upper and lower hull.
Categories: Communities

Bayesian Monte Carlo of Let's Make a Deal

Sat, 04/07/2012 - 13:03
This code illustrates Bayes' Theorem in action on the Let's Make a Deal problem, which several authors have used to illustrate Bayes' Theorem. (It's easy to search the internet for further explanation.) Run with the audit option to audit up to the first 100 games. Running without audit is faster...
Categories: Communities

Async HTTP server

Thu, 04/05/2012 - 05:53
Creating an asynchronous HTTP Server in F#.
Categories: Communities

JSON parsing with monads

Mon, 04/02/2012 - 17:56
JSON parsing with monads. See also "Expression parsing with monads" (http://fssnip.net/bi). Author URL: http://www.zbray.com
Categories: Communities

Single Life Annuity

Mon, 04/02/2012 - 03:48
A single life annuity function in F# including supporting functions such as probability of survival, pure endowment and discounted interest rate calculation....
Categories: Communities

In-place parallel QuickSort

Fri, 03/30/2012 - 08:16
It's fairly straightforward in-place QuickSort implementation which uses ThreadPool for parallelization. Still slower than library function Array.sortInPlace, though.
Categories: Communities

Sierpinski triangle, WPF

Fri, 03/16/2012 - 15:56
Draws a Sierpinski triangle using WPF
Categories: Communities

Poll a file until it is quiet

Fri, 03/16/2012 - 11:29
One of the problems with using FileSystemWatcher to detect new files and process them is that it tells you when the file starts being created, not when it finishes. Use this little function to poll the file until it stops being written to.
Categories: Communities

Haskell to F# (some operators)

Thu, 03/15/2012 - 18:22
Just toying around with making my F# code a little smaller with Haskell operators
Categories: Communities

Powerset

Thu, 03/15/2012 - 04:25
Powerset function followed by with tiny sample.
Categories: Communities

How many lines of code does your project contain?

Wed, 03/14/2012 - 09:58
A simple way to count the non-blank, non-comment lines in your code. (Doesn't use project files to identify source; just a wildcard. Doesn't support multi-line comments.)
Categories: Communities

MbUnit DSL

Tue, 03/13/2012 - 18:06
DSL for functional style, HUnit-like testing with MbUnit.
Categories: Communities

A simple sieve

Thu, 03/08/2012 - 02:55
A simple implementation for the sieve of Eratosthenes.
Categories: Communities

Remove duplicate list elements

Sat, 03/03/2012 - 23:09
Remove duplicate elements of a list. Returns list with first instance of duplicate elements, without modification of order except subsequent duplicate elements are omitted.
Categories: Communities

Lab3

Sat, 03/03/2012 - 16:20
Lab3
Categories: Communities

unit test in VS11 beta

Sat, 03/03/2012 - 11:56
Demo F# unit test in VS11 beta. In VS 2010 unit testing requires a hack whereby you add a c# test project to your solution and add to that project a linked item to the DLL of the F# project with the test methods.
Categories: Communities