Tesco in 70 lines of code
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
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
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
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
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
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
JSON parsing with monads
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
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
It's fairly straightforward in-place QuickSort implementation which uses ThreadPool for parallelization. Still slower than library function Array.sortInPlace, though.
Categories: Communities
Poll a file until it is quiet
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)
Just toying around with making my F# code a little smaller with Haskell operators
Categories: Communities
How many lines of code does your project contain?
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
Remove duplicate list elements
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
unit test in VS11 beta
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
